As a general rule, it's safer to put the literal first in statements
like this:
"admin".equals(user.getState())
If anyone wants to say that it looks/reads a bit funny, I'll agree.
It's an odd syntax, but it protects you from NPEs.
-Steve
Martin Strand wrote:
Well, if you get a NPE on this line:
user.getState().equals("admin")
then either "user" or "getState()" is null, right?
And, since "user" is definitely not null, your private String "state" is
obviously null.
Perhaps you should add something like this:
private String state = "initial state";
Martin
On Tue, 12 Sep 2006 15:52:25 +0200, Michael Wölm <[EMAIL PROTECTED]> wrote:
Hi,
Sadly, nobody have helped me with my problem. I dont know why. Am I too noob
or is my question incomprehensible? I would be pleased, if anybody could
give me an advice for my problem.
Greettings from Germany,
Michael Wölm
Original message is under this.
-----Ursprüngliche Nachricht-----
Von: m-woelm [mailto:[EMAIL PROTECTED]
Gesendet: Sonntag, 10. September 2006 16:13
An: 'Tapestry users'
Betreff: Question: Can not get access to object fields (Null Pointer
Exception)
Hi,
I hope anybody could explain me why I get a Null Pointer Exception, if I
want to get access to a field of an object. My method is similar to the
eshop-project of the book “Enjoying web dev with Tapestry”.
I tried to change the Listener-method onLogin as follows:
public void onLogin(IRequestCycle cycle) {
try {
User user = Users.getKnownUsers().getUser(email,password);
getUser().copyFrom(user);
if (user.getState().equals("admin"))
cycle.activate("Admin_Konsole");
else cycle.activate("User_Konsole");
} catch (AuthenticationException e) {
ValidationDelegate delegate = getDelegate();
delegate.setFormComponent(null);
delegate.record("Login failed", null);
}
}
Now I get an exception at point (user.getState().equals(“admin”)).
But why? user was set to the login-user two lines before? Why I can’t get
the field: private String state which I have set in User.class:
private String state;
public String getState() {
return this.state;
}
Thx ahead!
Michael Wölm
<mailto:[EMAIL PROTECTED]> [EMAIL PROTECTED]
Public Key: <http://gsg.ath.cx/~phoenix/downloads/MyPublicKey.asc>
href="http://gsg.ath.cx/~phoenix/downloads/MyPublicKey.asc
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]