You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Michael Wölm <ma...@m-woelm.de> on 2006/09/12 15:52:25 UTC
WG: Question: Can not get access to object fields (Null Pointer Exception) pls pls help!
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:mail@m-woelm.de]
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 cant 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
<ma...@m-woelm.de> mail@m-woelm.de
Public Key: <http://gsg.ath.cx/~phoenix/downloads/MyPublicKey.asc>
href="http://gsg.ath.cx/~phoenix/downloads/MyPublicKey.asc
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
AW: WG: Question: Can not get access to object fields (Null Pointer Exception) pls pls help!
Posted by m-woelm <ma...@m-woelm.de>.
hey, lot of thanks,
the state field was really null because the parameters were passed to the
constructor but I never saved the value...
By the reason I am a novice in tapestry, I had searched it everywhere but
not in that simple way...
Greetings,
Michael Wölm
-----Ursprüngliche Nachricht-----
Von: Steve Shucker [mailto:sshucker@vmsinfo.com]
Gesendet: Dienstag, 12. September 2006 16:03
An: Tapestry users
Betreff: Re: WG: Question: Can not get access to object fields (Null Pointer
Exception) pls pls help!
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 <ma...@m-woelm.de> 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:mail@m-woelm.de]
>> 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 cant 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
>>
>>
>> <ma...@m-woelm.de> mail@m-woelm.de
>>
>> Public Key: <http://gsg.ath.cx/~phoenix/downloads/MyPublicKey.asc>
>> href="http://gsg.ath.cx/~phoenix/downloads/MyPublicKey.asc
>>
>>
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>>
>>
>>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: WG: Question: Can not get access to object fields (Null Pointer
Exception) pls pls help!
Posted by Steve Shucker <ss...@vmsinfo.com>.
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 <ma...@m-woelm.de> 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:mail@m-woelm.de]
>> 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
>>
>>
>> <ma...@m-woelm.de> mail@m-woelm.de
>>
>> Public Key: <http://gsg.ath.cx/~phoenix/downloads/MyPublicKey.asc>
>> href="http://gsg.ath.cx/~phoenix/downloads/MyPublicKey.asc
>>
>>
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>>
>>
>>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: WG: Question: Can not get access to object fields (Null Pointer Exception) pls pls help!
Posted by Martin Strand <ma...@entcap.se>.
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 <ma...@m-woelm.de> 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:mail@m-woelm.de]
> 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
>
>
> <ma...@m-woelm.de> mail@m-woelm.de
>
> Public Key: <http://gsg.ath.cx/~phoenix/downloads/MyPublicKey.asc>
> href="http://gsg.ath.cx/~phoenix/downloads/MyPublicKey.asc
>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: Question: Can not get access to object fields (Null Pointer Exception) pls pls help!
Posted by Jesse Kuhnert <jk...@gmail.com>.
I'd say because user.getState() returns null. Right?
On 9/12/06, Michael Wölm <ma...@m-woelm.de> 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:mail@m-woelm.de]
> 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
>
>
>
> <ma...@m-woelm.de> mail@m-woelm.de
>
> Public Key: <http://gsg.ath.cx/~phoenix/downloads/MyPublicKey.asc>
> href="http://gsg.ath.cx/~phoenix/downloads/MyPublicKey.asc
>
>
>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>
--
Jesse Kuhnert
Tapestry/Dojo/(and a dash of TestNG), team member/developer
Open source based consulting work centered around
dojo/tapestry/tacos/hivemind. http://blog.opencomponentry.com