ERROR - NullPointerException

Problem 

NullPointerException is thrown by the program while accessing object element.

Cause 

Exception is thrown when program tries to access the object element or function using reference which has yet not been initialized or is still referencing null object.

For example -

public static void main(String[] args) {}
              MyClass my; // Can hold a reference but doesn’t yet
              my.m(5); // Throws an exception
}


Resolution

Make sure that the reference is pointing to some object or memory before accessing any element through it.