What is the name of the exception thrown when accessing a member of a null object?

The story behind the answer

The exception thrown when accessing a member through a null object reference is NullPointerException. Java raises this unchecked exception when code attempts an operation that requires an object, but the reference points to no object.

For example, calling user.getName() when user is null attempts to access an instance member through a null reference. Reading an instance field, invoking an instance method, or accessing an array through a null array reference can produce the same exception. The problem is not necessarily the member itself; it is the missing object used to reach it.

NullPointerException is part of the java.lang package, so Java programs do not need to import it explicitly. It extends RuntimeException, meaning the compiler does not require developers to catch or declare it. Modern Java versions may include a helpful message identifying which expression was null.

A common mix-up is IllegalArgumentException, which indicates that a method received an invalid argument. ClassCastException concerns an invalid type cast, while ArithmeticException commonly covers integer division by zero. Those exceptions describe different failures.

Source: Wikipedia · fact-checked Aug. 2026

Add question to a list

Choose a list to keep this question in: