NullPointerException
NullPointerException is a Java runtime exception raised when code attempts to use a null reference where an object is required.
100 Java Mistakes and How to Avoid Them
NullPointerException is the Java runtime exception raised when an operation dereferences or otherwise improperly uses a null reference.
- How it is used
- Frames null-related Java failures and prevention across APIs, varargs, initialization, and collections.
- How deep it goes
- Defines nullability concerns and develops focused failure mechanisms, stopping at prevention rules and tool guidance.
- Examples
- Uses null varargs casts, static field ordering, logger initialization, and Set.of contains(null) migration cases.
- What you can do after
- Diagnose/debug with it by tracing nullable flows, initialization order, varargs binding, and collection null policies.
Read how 100 Java Mistakes and How to Avoid Them explains NullPointerException →
Kotlin in Action, 2E
NullPointerException is a runtime exception raised when code dereferences a null reference where a non-null object is required.
- How it is used
- Uses nullability checks to prevent runtime dereference failures in JVM backends and Android applications.
- How deep it goes
- Explains nullable types and operators with a compact example, but defers deeper runtime and interoperability edge cases.
- Examples
- Demonstrates nullable and non-nullable String access and cites reduced Google Home crashes after Kotlin adoption.
- What you can do after
- Apply nullable types and Kotlin operators to prevent or explicitly handle possible null dereferences.
Read how Kotlin in Action, 2E explains NullPointerException →
Also covered in
- The Art of Code
- Troubleshooting Java: Read, debug, and optimize JVM applications
- Troubleshooting Java, Second Edition
What to know first
- exceptionAn exception is a runtime signal or value representing an abnormal condition that interrupts ordinary program flow and can be handled or propagated.
Related concepts
- Objects.requireNonNullproduced by · Objects.requireNonNull is a Java utility method that returns a non-null reference or throws NullPointerException when its argument is null.
- !! operatorproduced by · The !! operator is Kotlin's non-null assertion operator, which treats a nullable expression as non-null and throws an exception if it is null.
- optionaddressed by · An option type is a type that represents either a value of a specified type or its absence as distinct alternatives.
- exceptionkind of · An exception is a runtime signal or value representing an abnormal condition that interrupts ordinary program flow and can be handled or propagated.
- defensive programmingaddressed by · Defensive programming is an approach that anticipates invalid or unexpected inputs, states, and failures and uses checks or safeguards to handle them or limit their effects.
Questions about NullPointerException
What is NullPointerException?
NullPointerException is a Java runtime exception raised when code attempts to use a null reference where an object is required.
Which Manning books explain NullPointerException?
100 Java Mistakes and How to Avoid Them and Kotlin in Action, 2E.
What should I know before learning NullPointerException?
Manning books that teach NullPointerException usually introduce exception and Java first.
What is the difference between NullPointerException and NumberFormatException?
NullPointerException is a Java runtime exception raised when code attempts to use a null reference where an object is required. NumberFormatException is a Java runtime exception thrown when text cannot be converted to the required numeric format.
What is NullPointerException a kind of?
NullPointerException is a kind of exception. An exception is a runtime signal or value representing an abnormal condition that interrupts ordinary program flow and can be handled or propagated.
What is NullPointerException also called?
NullPointerException is also called null pointer exception.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.

