Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

null exception when using session

 
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
ExamLab Creator
Marshal
Pie
Posts: 4682
331
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
ExamLab Creator
Marshal
Pie
Posts: 4682
331
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
Pie
Posts: 50225
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe you mean if ( . . . != null && . . . ) . . .
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic