• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Nullpointer exception from

 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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;
 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic