I would like to know when NullPointerException comes in java. any help would be appreciated.
Raghu_Ganapm
0
Newbie Poster
Recommended Answers
Jump to PostWhen you try to use a reference variable or expression that does not contain a reference to an Object - ie contains null. This may be because it hasn't been initialised, or it may be the result of calling a method that returns null following an error or other condition …
Jump to PostA NPE will also occur if an object is defined (and also initialized) inside one method,
and you try to access it from another method.
Solution: Define the object outside of the method (to make it global).
All 7 Replies
JamesCherrill
4,733
Most Valuable Poster
Team Colleague
Featured Poster
hfx642
Ezzaral
2,714
Posting Sage
Team Colleague
Featured Poster
adarshcu
9
Junior Poster
hfx642
JamesCherrill
4,733
Most Valuable Poster
Team Colleague
Featured Poster
hfx642
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.