Erreur Exception in thread "main"
Yass
-
KX Messages postés 16761 Date d'inscription Statut Modérateur Dernière intervention -
KX Messages postés 16761 Date d'inscription Statut Modérateur Dernière intervention -
Bonjour, je dois créer un fichier texte avec Bloc notes et le lire sur eclipse( Réussi) ensuite, je doit créer un fichier binaire objet avec le texte créé et le mettre dans un arbre binaire (TreeSet) quand je le compile, il n'y a pas de signe d'erreur sur eclipse, cependant , j'obtiens cette erreur: Exception in thread "main" java.lang.NullPointerException
at CreationFichierBinaireObjet.main(CreationFichierBinaireObjet.java:30)
Je dois ensuite lire le fichier binaire créé, mais quand je le lit la console affiche []
Merci!
Code:
Ligne 30 : while(!nom.equalsIgnoreCase("//")){
Voici la classe categorie :
at CreationFichierBinaireObjet.main(CreationFichierBinaireObjet.java:30)
Je dois ensuite lire le fichier binaire créé, mais quand je le lit la console affiche []
Merci!
Code:
import java.awt.Point; import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.FileReader; import java.io.IOException; import java.io.ObjectOutputStream; import java.util.LinkedList; import java.util.TreeSet; public class CreationFichierBinaireObjet{ public static void main(String[] args) throws IOException { String nom; BufferedReader fluxEntree = new BufferedReader(new FileReader("texte.txt")); do { nom = fluxEntree.readLine(); } while (nom != null); fluxEntree.close(); TreeSet<Categorie>arbreCategories = new TreeSet<Categorie>(); Categorie cat= null; while(!nom.equalsIgnoreCase("//")){ if(nom.charAt(0)=='*'){ arbreCategories.add( cat = new Categorie(nom.substring(1).toLowerCase())); }else{ cat.getInventions().add(new Invention(nom ,fluxEntree.readLine(),Integer.parseInt(fluxEntree.readLine()))); } nom = fluxEntree.readLine(); } fluxEntree.close(); System.out.println(arbreCategories); FileOutputStream binObj = new FileOutputStream("binObj.dat"); ; ObjectOutputStream fluxObjet = new ObjectOutputStream(binObj); fluxObjet.writeObject(arbreCategories); fluxObjet.close(); }}
Ligne 30 : while(!nom.equalsIgnoreCase("//")){
Voici la classe categorie :
import java.util.HashSet; import java.util.Iterator; import java.io.Serializable; public class Categorie implements Serializable { private static final long serialVersionUID = 1L; private String nomCategorie; private HashSet<Invention>inventions; public Categorie(String categorie){ nomCategorie = categorie; inventions = new HashSet<Invention>(); } public String getNomCategorie(){ return nomCategorie; } public HashSet<Invention> getInventions(){ return inventions; } public int compareTo (Categorie nomCategorieTemp){ return nomCategorie.compareToIgnoreCase(nomCategorieTemp.getNomCategorie()); } public String toString(){ return"Categorie:" +nomCategorie+"\n"+inventions; } }
A voir également:
- Erreur Exception in thread "main"
- Deco in paris avis ✓ - Forum Consommation & Internet
- Déco in paris site fiable ???? - Forum Consommation & Internet
- Girl in the basement streaming vf - Forum Cinéma / Télé
- Playback error reconnect in 3s (1/5) francais - Forum Box et Streaming vidéo
- Delai paiement le bon coin remise en main propre - Forum Vos droits sur internet