wood burning stoves 2.0*
The moose likes Java in General and the fly likes boolean method returns null - NullPointerException Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "boolean method returns null - NullPointerException" Watch "boolean method returns null - NullPointerException" New topic
Author

boolean method returns null - NullPointerException

Ramesh Kumar Swarnkar
Ranch Hand

Joined: Sep 15, 2003
Posts: 84
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

Joined: Jan 01, 2009
Posts: 874


Ramesh,

boolean isPresent = ObjectA.IsIncluded();


Its not boolean that returns null ,its ObjectA , check if its been initialised
Ramesh Kumar Swarnkar
Ranch Hand

Joined: Sep 15, 2003
Posts: 84
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

Joined: Jan 01, 2009
Posts: 874



You are welcome.

" java.lang.NullPointerException " almost always happens when we invoke a method on the object which is null.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38513
    
  23
There are lots more reasons for NullPointerExceptions. I am writing an article about it
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: boolean method returns null - NullPointerException