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
nullas if he were a vector; - Access or modify the elements of a
nullas if he were a vector; - Launch
nullin place of ajava.lang.Throwable. - Iterate
nullas if it were an array or a collection. - Use
null(or a variable or expression resulting innull) in a blocksynchronized. - Try to convert a variable or expression that results in
nulla 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: