This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Null Pointer Exception Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Null Pointer Exception" Watch "Null Pointer Exception" New topic
Author

Null Pointer Exception

Vandiyadevan senthan
Ranch Hand

Joined: Nov 11, 2003
Posts: 37
Hi,
Can anyone tell me ,when will the Null Pointer Exception throw?
Thanx in advance.
regards,
Vandiyadevan
Vicken Karaoghlanian
Ranch Hand

Joined: Jul 21, 2003
Posts: 522
A NullPointerException is thrown when you try to reference a null Object variable (an object that is not there).


- Do not try and bend the spoon. That's impossible. Instead, only try to realize the truth. <br />- What truth? <br />- That there is no spoon!!!
Kim Kantola
Ranch Hand

Joined: May 17, 2001
Posts: 274
Another example would be when you try to call a method of an object when the object is null

The call of the intValue() method of the Integer object x will throw a Null Pointer exception since x is null. If you are getting an object from another method and are not sure if it would be null or not, this is a good idea so that you won't hit the exception :
Sadanand Murthy
Ranch Hand

Joined: Nov 26, 2003
Posts: 382
Originally posted by Vicken Karaoghlanian:
A NullPointerException is thrown when you try to reference a null Object variable (an object that is not there).

Vandiyadevan senthan ,
Keep in mind that even if an array obj is initialized, you may get NPE.
Example:
(where i >=0 and i <5) will give NPE since SomeClass[ i ] has not been initialized & is null.


Ever Existing, Ever Conscious, Ever-new Bliss
 
jQuery in Action, 2nd edition
 
subject: Null Pointer Exception
 
Similar Threads
double Type of Value in JTable
SCJP Brainteaser (2)
problem in running exec() from servlet
explain me this code
problem to display session attribute