jQuery in Action, 2nd edition*
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 Murach's Java Servlets and JSP this week in the Servlets 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: 3018
    
  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.


Founder of ExamLab and Systemup
See how I can help you to become an awesome programmer
Devaka Cooray
ExamLab Creator
Saloon Keeper

Joined: Jul 29, 2008
Posts: 3018
    
  35

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

Joined: Oct 13, 2005
Posts: 37950
    
  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