File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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 Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "null exception when using session" Watch "null exception when using session" New topic

null exception when using session

Jahar Heard

Joined: Jan 09, 2010
Posts: 20

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: 2891

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
My Home Page -- Twitter Profile -- JavaRanch FAQ -- How to Ask a Question
Devaka Cooray
ExamLab Creator
Saloon Keeper

Joined: Jul 29, 2008
Posts: 2891

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

Joined: Oct 13, 2005
Posts: 36599
Maybe you mean if ( . . . != null && . . . ) . . .
It is sorta covered in the JavaRanch Style Guide.
subject: null exception when using session
Similar Threads
how to bring variable from previous session to next session
ssession doesn't seem to be storing/holding object on server-works local
syntax and error in ncf log
Using sessions for authentication
Servlet API 2.2