Solve the problem of java.lang.ExceptionInInitializerError error
Start a project today... An error was reported when it started... After checking for a long time, the error message kept saying that there was an error in hibernate cache management...
Finally, check the log at startup and find that the program reports Java.lang.ExceptionInInitializerError
The reason for viewing is that you modify the static constants. When the system starts, the result of the error in obtaining the properties value automatically causes an error when the code is compiled.
Error code:
public static final String message = getMessage("ok_oj");Cause analysis:
message is a static constant. When the system compiles this class, it will first load the static constant and store it in the static memory domain.
However, because getMessage returns a null at startup, it causes an error java.lang.ExceptionInInitializerError
Let's talk about the error message java.lang.ExceptionInInitializerError
I rarely encountered any exception information before, so I searched online for this error indicating initialization exception and null pointer error
View the API which describes this exception
A signal that an unexpected exception occurred in the static initialization program. Throwing ExceptionInInitializerError indicates that an exception occurred during calculating the static initial value or the initial value of the static variable.
public class ExceptionInInitializerErrorextends LinkageError
It can be seen that he inherited from LinkageError
The LinkageError has given a description and it is obvious that the problem is pointed out.
A subclass of LinkageError indicates that one class depends on another to some extent; however, after compiling the previous class, the latter class changes in compatibility.
Thank you for reading, I hope it can help you. Thank you for your support for this site!