Exception java
cabistos
Messages postés
26
Statut
Membre
-
cabistos Messages postés 26 Statut Membre -
cabistos Messages postés 26 Statut Membre -
Bonjour,
mon code marche très bien sauf si la condition sur la derniere ligne du fichier source devient == true ; l'exception : Exception in thread "main" java.lang.NullPointerException
at allégerfile.maClass.main(maClass.java:35) est levé
svp aidez moi
voici mon code :
mon code marche très bien sauf si la condition sur la derniere ligne du fichier source devient == true ; l'exception : Exception in thread "main" java.lang.NullPointerException
at allégerfile.maClass.main(maClass.java:35) est levé
svp aidez moi
voici mon code :
public static void main (String[] args) throws IOException {
// lecture fichier //
BufferedReader in = new BufferedReader(new FileReader("D://pfe//copie.txt"));
out = new PrintWriter (new FileWriter ("D://mail.txt"));
out2 = new PrintWriter (new FileWriter("d://Etrangé.txt"));
out3 = new PrintWriter (new FileWriter("d://Editable.txt"));
String line = in.readLine();
// défalcation //
//compte mail //
while (line != null){
if ((line.startsWith("EXSTRS01")) && (line.substring(780,791).startsWith("EMAILVIDE")== false) && (line.substring(830,831).startsWith("O")))
{ out.println(line); String s = in.readLine() ;
while (s.startsWith("EXSTRS01")==false )
{ out.println(s);
s = in.readLine();}}
else if ((line.startsWith("EXSTRS01"))&&(line.substring(696,746).startsWith("OEMAILVIDE")== false)&&(line.substring(746,747).startsWith("O")))
{ out.println(line); String s = in.readLine() ;
while (s.startsWith("EXSTRS01")==false){ out.println(s);s = in.readLine();
}
}
line = in.readLine();
}
in.close();
out.close();
A voir également:
- Exception java
- Jeux java itel - Télécharger - Jeux vidéo
- Waptrick java football - Télécharger - Jeux vidéo
- Waptrick java voiture - Télécharger - Jeux vidéo
- Java apk - Télécharger - Langages
- Eclipse java - Télécharger - Langages
2 réponses
Bonjour,
Lorsque tu fais
Lorsque tu fais
String s = in.readLine();il faut tester si
s==nullcomme tu l'as fait pour
line. Sinon effectivement tu vas te prendre un NullPointerException pour la dernière ligne.
cabistos
Messages postés
26
Statut
Membre
merci KX , une dernière chose si le fichier source contient une ligne qui commence par EXSTRS01 sélectionné par le 1er if et la 2 eme EXSTRS01 répond a la condition du 2 eme if ; alors la 2 eme sera ignoré . autrement si j'ai a copier 2 comptes successives par 2 if différentes ça marche pas