Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
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
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: 3060
    
  38

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: 3060
    
  38

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

Joined: Oct 13, 2005
Posts: 38481
    
  23
Maybe you mean if ( . . . != null && . . . ) . . .
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: null exception when using session