aspose file tools*
The moose likes JDBC and the fly likes java.lang.NullPointerException Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "java.lang.NullPointerException" Watch "java.lang.NullPointerException" New topic
Author

java.lang.NullPointerException

Farakh khan
Ranch Hand

Joined: Mar 22, 2008
Posts: 740
My following code works if one or more checkboxes selected. If the selection is empty then it throws:
java.lang.NullPointerException

>
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18907
    
    8

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

Joined: Mar 06, 2001
Posts: 13459

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

Joined: Mar 22, 2008
Posts: 740
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: java.lang.NullPointerException