What causes "nullpointerexception" in java?

Example:

String str = null;
str.length();
This error occurs when you try to invoke a method or property on a null object.

Solution:

Ensure the object is initialized before invoking methods on it.

Beginner's Guide to Java