Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

boolean method returns null - NullPointerException

 
Ramesh Kumar Swarnkar
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have an issue, which as follows:

ObjectA contains a method [boolean IsIncluded()]which is supposed to return a boolean value.
But since the boolean value is not set into that variable which being returned by that method, neighter it is initialised.
As a consquence it returns 'null';

boolean isPresent = ObjectA.IsIncluded();

The aboce line where it is being called, throws java.lang.NullPointerException.
Any suggetion how to avoid this null pointer Exception where it is being called ? Any idea on its type casting which may avodi this problem ?

A quick response would be highly appreciated.
thansk in advance,
Ramesh.
 
Balu Sadhasivam
Ranch Hand
Posts: 874
Android Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Ramesh,

boolean isPresent = ObjectA.IsIncluded();


Its not boolean that returns null ,its ObjectA , check if its been initialised
 
Ramesh Kumar Swarnkar
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Balu you are great.
Yes it was the object NULL. I dont know how missed that check !
I am very much thankfull to you for your promt help.

thanks once again friend .

-Ramesh
 
Balu Sadhasivam
Ranch Hand
Posts: 874
Android Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


You are welcome.

" java.lang.NullPointerException " almost always happens when we invoke a method on the object which is null.
 
Campbell Ritchie
Sheriff
Posts: 51390
87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are lots more reasons for NullPointerExceptions. I am writing an article about it
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic