MY mENU


Friday 10 February 2012

NullPointerException


NullPointerException occurs when below criteria happens

1) Throw when an application attempt to use a null in a case where an object is required

2) Calling the instance method of null object

3) Accessing or Modifying the field of null object

4) Taking the length of null as if it were an array

5) Accessing or modifying the slot of null as if it were an array

6) Throwing null as if it were a throwable value

Handle

Suppose String name = null

if i will do this

if (name.equals("srinivas")) --> it throw null pointer Exception

to avoid this you can use the above statement as below

if("srinivas".equals(name))

No comments:

Post a Comment