File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Other Application Frameworks and the fly likes Nullpointer exception from Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Frameworks » Other Application Frameworks
Bookmark "Nullpointer exception from " Watch "Nullpointer exception from " New topic
Author

Nullpointer exception from

chandrakant karale
Ranch Hand

Joined: Nov 21, 2007
Posts: 41
I have a method call which is throwing NullpointerException at

return(Integer)getSqlMapClientTemplate().queryForObject("selectBenefitCountWhereNotXInResRecThread",requestIdentifier);


The query is supposed to return a integer value. If the requestIdentifier is absent in the table it will return a NULL object(as per ibatis doc).
Can the result of IF statement be true if the value returned by query is NULL?

NullPointer exception will only be thrown if the query returns null as null type will casted to Integer, and then before return , unboxed to int, which will throw an exception.

But for this to happen the IF statement needs to evaluate to true. How it evaluates to true.





I understand that multiple calls to the same method in if statement are not proper; but need to root cause this;
Deepesh Deomurari
Greenhorn

Joined: Oct 29, 2008
Posts: 17
Yes. You should use variable. Please specify line on which you are getting NullPointerException

1. What will happen if getSqlMapClientTemplate() is null!
2. How can you compare Object to a String(" ")? Not significant
3. count can never be null. It can be 0.


Deepesh Deomurari<br />"When Going Gets Tough,<br />The Tough, Gets Going."
SCJP 1.5 -94%
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Nullpointer exception from