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
- Read the stack trace: find line and variable.
- Check the variable beforehand or use
Optional. - Check constructors and initialisation.
See also: Instantiate, Initialise, Java