EMZETT.
Login

NullPointerException (Java)

In short: A reference pointing to null was accessed.

In more detail: One of the most frequent Java errors.

In Depth

Possible causes

  • Object not initialised (instantiate).
  • Method returns null.
  • Wrong order of initialisation.

Solutions

  1. Read the stack trace: find line and variable.
  2. Check the variable beforehand or use Optional.
  3. Check constructors and initialisation.

See also: Instantiate, Initialise, Java