Bonjour!
Voila je débute en informatique et je rencontre un probleme pour executer un programme pour lire un fichier.
J'utilise le logiciel Eclipse.
Voici mon code:
Et voici les erreurs que me met eclipse quand j'essai de faire marcher le code :
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
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67 package Num; import java.io.File; import java.io.FileNotFoundException; import java.util.Locale; import java.util.Scanner; public class Test{ public int NbSommets; public int NbArcs; public int NumeroSommetS; public int NumerosommetT; public Scanner scan; public Test() throws FileNotFoundException{ Scanner scan = new Scanner(new File("C:\\Documents and Settings\\Jiybee\\Mes documents\\Opti Num\\data0.dat")); scan.useLocale(Locale.US); } public void LireFichier(){ NbSommets=scan.nextInt(); NbArcs= scan.nextInt(); NumeroSommetS= scan.nextInt(); NumerosommetT=scan.nextInt(); int S=0; /** * i nbre successeur */ while (scan.hasNext()){ int i = scan.nextInt(); Node[] tabS = new Node[i]; for (int j=1;j<=i;j++){ Node Noeud = new Node(scan.nextInt(), 1-scan.nextDouble()); tabS[j]= Noeud; } S++; } } public static void main(String[]args) throws FileNotFoundException{ Test jb = new Test(); jb.LireFichier(); } /** * Classe interne représentant les Noeuds. */ private static class Node { int NSommets; double proba; public Node(int NSommets,double proba) { this.NSommets = NSommets; this.proba = proba; } } }
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3 Exception in thread "main" java.lang.NullPointerException at Num.Test.LireFichier(Test.java:23) at Num.Test.main(Test.java:45)
J'esper que vous pourrez m'aider
Merci d'avance
Partager