Java – NullPointerException

NullPointerException: Thrown when an application attempts to use a `null` object reference where an object is required.
Example:

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

No images available.