top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How to handle nullpointer exception in java?

+1 vote
218 views
How to handle nullpointer exception in java?
posted Oct 3, 2013 by Nagarajuk

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

Try catching it

catch (NullPointerException npe) {
            npe.printStackTrace();
}

or

catch (IOException | NullPointerException npe) // you can multi-catch exceptions, java7 new feature
   npe.printStackTrace();
}    

Now the point is try to avoid this situation please go through this link
http://howtodoinjava.com/2013/04/05/how-to-effectively-handle-nullpointerexception-in-java/

answer Oct 3, 2013 by Salil Agrawal
...