w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
java.lang.ExceptionInInitializerError Caused by: java.lang.NullPointerException

Why it is throwing NullPointerException and not ArrayIndexOutOfBoundException.

Because your are not initialized the array.

Initialize array

   static int x[] = new int[10];

Reason for NullPointerException:

Thrown when an application attempts to use null in a case where an object is required. These include:

  • Calling the instance method of a null object.
  • Accessing or modifying the field of a null object.
  • Taking the length of null as if it were an array.
  • Accessing or modifying the slots of null as if it were an array.
  • Throwing null as if it were a Throwable value.

You hit by the bolder point, since the array is null.





© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.