Hii all :)
How are u?? :)
I have a little a problem with String object in this class (You can say its a homework ^__^ ).
public class Personne {
private String nom;
private String prenom;
private int age;
public Personne(){
this(null, null, 0);
}
public Personne(String nom, String prenom, int age){
setNom(nom);
setPrenom(prenom);
setAge(age);
}
public void setNom(String nom){
this.nom = new String(nom);
}
public void setPrenom(String prenom){
this.prenom = new String(prenom);
}
public void setAge(int age){
this.age = age;
}
public String getNom(){
return this.nom;
}
public String getPrenom(){
return this.prenom;
}
public int getAge(){
return this.age;
}
public String toString(){
System.out.print("Nom : " + this.getNom() + ", Penom : " + this.getPrenom() + ", Age : " + this.getAge() + " ");
return null;
}
}
When i call the class personne with the Personne() i get these errors in compiling-time :
Exception in thread "main" java.lang.NullPointerException
at java.lang.String.<init>(Unknown Source)
at Personne.setNom(Personne.java:18)
at Personne.<init>(Personne.java:12)
at Personne.<init>(Personne.java:8)
at Main.main(Main.java:4) // The line wich i inisialize my object in my main method.
can someone help me??
Thank you alll ^__^
Edited by: La VloZ on 18 mai 2013 22:50
Edited by: La VloZ on 18 mai 2013 22:51
Edited by: La VloZ on 18 mai 2013 22:51
Edited by: La VloZ on 18 mai 2013 22:53
Edited by: La VloZ on 18 mai 2013 22:55