Java – NullPointerException

NullPointerException: Thrown when the JVM attempts to access a method or field of a null object.
Example:

String str = null;
try {
int length = str.length();
} catch (NullPointerException e) {
System.out.println("Caught NullPointerException: " + e.getMessage());
}

No images available.