Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

String problem java.lang.NullPointerException

La VloZMay 18 2013 — edited May 19 2013
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
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 16 2013
Added on May 18 2013
7 comments
2,984 views