Can somebody tell me whats wrong with the following class?
--------------------------------------------------------------
public class Account
{
private Key myKey;
private String username;
private String password;
public Account(Chat serverRef, String user, String pass)
{
myKey = new Key(serverRef);
username = user;
password = pass;
}
public Account(Chat serverRef)
{
myKey = null;
username = null;
password = null;
}
public String getUsername()
{
return username;
}
public String getPassword()
{
return password;
}
public Key getKey()
{
return myKey;
}
}
--------------------------------------------------------
The problem is, I do smth like:
Account myAccount = new Account(aChatServerObject, myUsername, myPassword); // it is fine but not until I do:
Key temp = myAccount.getKey(); // then it returns java.lang.nullpointerException. Why is that??? I cant see whats wrong with that though~~~ Somebody?
public Account(Chat serverRef)
constructor. That constructor does NOT initialize the key field (though it probabyl should).