Bonjour à tous,
Je voudrais remplir un JList à l'aide d'un fichier txt. J'ai alors mis ces méthodes en place :
initialisation du JList:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
private JList getJListNomPrenom() {
		if (jListNomPrenom == null) {
			jListNomPrenom = new JList();
			jListNomPrenom.setBounds(new Rectangle(1, 1, 170, 421));
			Vector<String> data = loadData( "NomPrenom.txt" );
			jListNomPrenom.setListData(data);
		}
		return jListNomPrenom;
	}
Méthode pour la lecture du fichier text:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
public Vector<String> loadData(String filename) {
		// TODO Auto-generated method stub
		Vector<String> data = loadData( "NomPrenom.txt" );
		data = new Vector<String>();
		FileReader fin = null;
		try {
		java.net.URL url = getClass().getResource( filename );
		fin = new FileReader(url.toURI().getPath());
		} catch (Exception e) {
		System.out.println("Problème de chargement du fichier " + filename + ": " + e);
		return null;
	}
		Scanner sc = new Scanner(fin);
		while (sc.hasNext()) {
		data.add(sc.nextLine());
}
		sc.close();
		try {
		fin.close();
		} catch (IOException ex) {
		System.out.println("problem closing FileReader in");
		}
		return data;
	}
Malheureusement au lancement du programme, j'ai cette erreur:
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
...
Pouvez_vous m'aider s'il vous plaît à corriger cette erreur