简体   繁体   English

没有静态初始化程序的java.lang.ExceptionInInitializerError

[英]java.lang.ExceptionInInitializerError without a static initializer

I get a java.lang.ExceptionInInitializerError but I don´t have a static initializer. 我收到java.lang.ExceptionInInitializerError,但没有静态初始值设定项。

Code: 码:

public static final File STANDARD_INDEX_FILE = new File(HTMLFileLoader.class.getClassLoader().getResource("index.html").getPath()); // Line 16 

The HTMLFileLoader class is empty. HTMLFileLoader类为空。

Exception: 例外:

Exception in thread "main" java.lang.ExceptionInInitializerError
    at net.guardian.Guardian.main(Guardian.java:12)
Caused by: java.lang.NullPointerException
    at net.guardian.socket.MainSocket.<init>(MainSocket.java:16)
    at net.guardian.socket.MainSocket.<clinit>(MainSocket.java:24)
    ... 1 more

This: 这个:

public static final File STANDARD_INDEX_FILE = new File(HTMLFileLoader.class.getClassLoader().getResource("index.html").getPath()); // Line 16 

is exactly the same as this: 与此完全相同:

public static final File STANDARD_INDEX_FILE;

static {
  STANDARD_INDEX_FILE = new File(HTMLFileLoader.class.getClassLoader().getResource("index.html").getPath()); // Line 16 
}

As in, this is what it looks like in the compiled code. 就像在编译后的代码中那样。

As such, you do have a static initializer; 因此,您确实有一个静态初始化程序。 and the exception is occuring somewhere in that initializer block. 并且该初始化程序块中的某处发生了异常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM