• Post Reply Bookmark Topic Watch Topic
  • New Topic

null exception when using session  RSS feed

 
Jahar Heard
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Posts: 5521
691
Chrome Eclipse IDE Google App Engine IntelliJ IDE jQuery Postgres Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Devaka Cooray
Marshal
Posts: 5521
691
Chrome Eclipse IDE Google App Engine IntelliJ IDE jQuery Postgres Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Vladislav Rashkov,
Your post was moved to a new topic.
 
Campbell Ritchie
Sheriff
Posts: 55351
157
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe you mean if ( . . . != null && . . . ) . . .
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!