Follow Us
  • Register
Errorbase is a collaborative writing project, that aims to build the largest trouble-shooting guide about all kinds of error messages.


0 votes

This error message is appeared in Java when a null object has been tried to access or modify. This is one of the most common exceptions in Java.
String p = null;


String[] strArray = new String[5];

This kind of usage returns java.lang.NullPointerException.

requested by (170k points)
edited by

1 Solution

0 votes

In order to solve the problem you must find the line that causes this exception. Java shows the line number of the error in the error message.
Exception in thread "main" java.lang.NullPointerException
at SomePackage.SomeClass.main(

In most of the IDEs (Integrated Development Environment) you can click the line number and reach the error immediately. By this way you can see which variable is null and you can initialize that variable. Of course this is not the only solution for this exception, since there are lots of causes for java.lang.NullPointerException, however most of the problems can be solved by this approach.

solved by (170k points)
edited by