相关疑难解决方法(0)

java.lang.ExceptionInInitializerError由以下引起:java.lang.NullPointerException

这是来自OCJP的例子.我写了以下代码

public class Test {

  static int x[];

  static {
     x[0] = 1;
  }

  public static void main(String... args) {
  }        
}       
Run Code Online (Sandbox Code Playgroud)

输出: java.lang.ExceptionInInitializerError

引起:java.lang.NullPointerException at x[0] = 1;

它为什么扔NullPointerException而不是ArrayIndexOutOfBoundException.

java exception nullpointerexception

7
推荐指数
1
解决办法
8万
查看次数

标签 统计

exception ×1

java ×1

nullpointerexception ×1