| Author |
boolean method returns null - NullPointerException
|
Ramesh Kumar Swarnkar
Ranch Hand
Joined: Sep 15, 2003
Posts: 83
|
|
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: 83
|
|
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: 32611
|
|
There are lots more reasons for NullPointerExceptions. I am writing an article about it
|
 |
 |
|
|
subject: boolean method returns null - NullPointerException
|
|
|