wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes null exception when using session Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "null exception when using session" Watch "null exception when using session" New topic
Author

null exception when using session

Jahar Heard
Greenhorn

Joined: Jan 09, 2010
Posts: 20
HI!

I'm when I use session I do this.



this code is after the login, but it gave me null exception error, on line with the second if

Any Ideas ?
Devaka Cooray
ExamLab Creator
Saloon Keeper

Joined: Jul 29, 2008
Posts: 3028
    
  35

Vladislav Rashkov wrote:

This is something similar to saying "if nameSessed IS null, AND nameSessed.isEmpty() is true...."

If nameSessed is null, trying to acces isEmpty() method of that nulled reference throws a NullPointerException. If you need to check "null OR empty", you should use the short-circuit 'or' operator (||), so the second operand (nameSessed.isEmpty()) will not be checked, if the first operand (nameSessed==null) is true.

Not related to Servlets. Moving this to the Beginning Java forum.


Author of ExamLab ExamLab - a free SCJP / OCPJP exam simulator
What would SCJP exam questions look like? -- Home -- Twitter -- How to Ask a Question
Devaka Cooray
ExamLab Creator
Saloon Keeper

Joined: Jul 29, 2008
Posts: 3028
    
  35

Vladislav Rashkov,
Your post was moved to a new topic.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38087
    
  22
Maybe you mean if ( . . . != null && . . . ) . . .
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: null exception when using session
 
Similar Threads
Using sessions for authentication
Servlet API 2.2
syntax and error in ncf log
how to bring variable from previous session to next session
ssession doesn't seem to be storing/holding object on server-works local