What is "nullpointerexception"

The NullPointerException is the exception in Java when attempting to manipulate a reference null as if she were indeed an object.

Occurrence:

  • Calling an instance method of a null object;
  • Accessing or modifying an attribute of a null object;
  • Take the size of one null as if he were a vector;
  • Access or modify the elements of a null as if he were a vector;
  • Launch null in place of a java.lang.Throwable.
  • Iterate null as if it were an array or a collection.
  • Use null (or a variable or expression resulting in null) in a block synchronized.
  • Try to convert a variable or expression that results in null a value of a primitive type by means of autounboxing.

Applications must launch instances of this exception to indicate other illegal uses of a null reference.

Usually the occurrence of a NullPointerException denotes a programming error, and therefore the same should be avoided instead of being treated.

In some languages the name may be a little different. In C# it is NullReferenceException, but the principle is the same.

We have questions here that we can consider as canonical and reading them will learn a lot of what you need to solve your problem: