catch nullpointerexception code example
Example 1: NullPointerException
TestObject a = new TestObject();String b = a.getTestResult();b.toString();
Example 2: nullpointerexception
public class MyClass{
private Object iAmNowNull;
private Object iAmInitialized=new Object();
public void test(){
System.out.println(iAmInitialized.toString());
System.out.println(iAmNull.toString());
}
Example 3: nullpointerexception
public class MyClass{
private Object iAmNull;
private Object iAmInitialized=new Object();
public void test(){
System.out.println(iAmInitialized.toString());
System.out.println(iAmNull.toString());
}
}