Resolve the java.lang.ExceptionInInitializerError error

  • 2020-05-27 05:30:12
  • OfStack

Resolve java.lang.ExceptionInInitializerError error

Start a project today... Error reporting at startup... I have been looking up the error message 1 for a long time.

Finally, if you look at the log at startup, you'll find that the program reports Java.lang.ExceptionInInitializerError

Finally, I modified the static constant. When the system was started, it automatically got the properties value. As a result, it got the wrong properties value, which caused an error when the code was compiled

Error code:

public static final String message = getMessage("ok_oj"); 

Reason analysis:

message is a static constant. When the system compiles this class, the first static constant is loaded into the memory static field.

But because getMessage returned 1 null at startup, it caused an error to report java.lang.ExceptionInInitializerError

Here is the java.lang.ExceptionInInitializerError error

I rarely encountered such an exception before so I searched the Internet for this error which means initialization exception and null pointer error

See API for a description of this exception

A signal that an unexpected exception occurred in a static initializer. Throwing ExceptionInInitializerError indicates that an exception occurred during the calculation of a static initial value or the initial value of a static variable.

public class ExceptionInInitializerErrorextends LinkageError 

It can be seen that he inherited LinkageError

For LinkageError there is a description that clearly points to the problem

A subclass of LinkageError indicates that one class is dependent on the other to a certain extent; However, after compiling the first class, the last class has changed incompatibly.

Thank you for reading, I hope to help you, thank you for your support of this site!

Related articles: