Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

java.lang.NullPointerException

 
Farakh khan
Ranch Hand
Posts: 833
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My following code works if one or more checkboxes selected. If the selection is empty then it throws:
java.lang.NullPointerException

>
 
Paul Clapham
Sheriff
Posts: 21107
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Start by looking at the line of code where the exception is thrown. That should tell you which variable is null, and then you should modify your code to test whether the variable is null before using it.

(Hint: we don't know which line of code it is.)
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Defensive programming:
this isn't directly related to your problem, but rather than writing variable.equals("string") try to get into the practice of writing "string".equals(variable)
They are nearly the same but the latter returns false for null rather than throwing an NPE.
You can do the same with many Java classes eg new Integer(0).equals(var)
 
Farakh khan
Ranch Hand
Posts: 833
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
David O'Meara wrote:Defensive programming:
this isn't directly related to your problem, but rather than writing variable.equals("string") try to get into the practice of writing "string".equals(variable)
They are nearly the same but the latter returns false for null rather than throwing an NPE.
You can do the same with many Java classes eg new Integer(0).equals(var)


Thanks the problem fixed


Best Regards
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic