NullPointerException in Java — What It Means and How to Fix It
What Java's NullPointerException means and how to fix it.
Published November 1, 2026
NullPointerException is thrown when code attempts to use a reference that points to null, such as calling a method on it.
Key points
- Read the full stack trace from the top — it names the exact class, method, and line where the exception originated
Example
String s = null;\ns.length(); // NullPointerException