This is from OCJP example. I have written a following code
public class Test {
static int x[];
static {
x[0] = 1;
}
public static void main(String... args) {
}
}
Output: java.lang.ExceptionInInitializerError
Caused by: java.lang.NullPointerException at x[0] = 1;
Why it is throwing NullPointerException and not ArrayIndexOutOfBoundException.