Java For Android Tutorial #10:Nullpointerexception
Code:
package com.example; public class java { public static void main(String[] str) { String[] names = null; try { System.out.println(names[0]); } catch(NullPointerException e){ System.out.println("You are trying to access a variable or an Array or an Object which is null"); } }}
In this tutorial, I have taken a simple example of an array, tried to produce a nullpointerexception. This type of exception is common while handling objects. There is number of reasons, why this exception occurs. Most important is the improper initialization of the objects. But you have to properly handle the objects for handling nullpointerexception.
Comments
Post a Comment