SECURITY WARNING: Never run commands you don't understand. Always review code before execution. Use at your own risk.
Java New Added 10 September 2026

Java: NoClassDefFoundError: Could not initialize class X

This is not a missing class. The class was found, its static initialiser ran and threw, and every later use reports this instead. The real exception appears only the first time, often much earlier in the log, and is usually a missing config value, a failing static block or an incompatible dependency.

Quick fix

Read the commands before running them. Anything that restarts a service, deletes data or changes permissions should be tried on a non-production system first.

Quick fix
# Find the first failure, not the repeat
grep -n -m1 -B5 -A30 "ExceptionInInitializerError" app.log

// Wrap the static work so the cause is not lost
static {
    try { CONFIG = load(); }
    catch (Exception e) { throw new ExceptionInInitializerError(e); }
}

# A genuinely absent class throws ClassNotFoundException instead: check which
unzip -l app.jar | grep -i MyClass
jar tf app.jar | grep -i MyClass

# Common causes: a native library that failed to load, a JCE policy problem,
# or a class compiled against a different version of a dependency
java -verbose:class -jar app.jar | grep MyClass
mvn dependency:tree -Dincludes=com.example

How to diagnose Java errors

Java errors concentrate at the class loading boundary (ClassNotFoundException, NoClassDefFoundError, UnsupportedClassVersionError) and around resource pools under load. Class loading errors are almost always classpath or version problems rather than missing code. UnsupportedClassVersionError in particular is a pure bytecode-version mismatch and tells you exactly which JDK compiled the class.

If the quick fix above does not resolve it, work through these steps. They apply to this whole class of error, not just to this one message, which is usually what saves the time.

  1. Print the actual runtime version with java -version and compare it against your build target. Major bytecode version 65 is Java 21, 61 is Java 17, 52 is Java 8.
  2. Inspect the resolved dependency tree (mvn dependency:tree, gradle dependencies) to find duplicate or conflicting versions of the same library.
  3. For pool exhaustion, log pool metrics (HikariCP exposes active, idle and pending counts). Exhaustion means connections are not being returned, which is a try-with-resources problem.
  4. Enable -verbose:class temporarily to see which jar a class is loaded from when two versions are on the classpath.
  5. Capture a heap dump on OOM with -XX:+HeapDumpOnOutOfMemoryError and analyse it rather than raising -Xmx blindly.

Tools worth reaching for

  • mvn dependency:tree
  • jcmd / jstack / jmap
  • -verbose:class
  • Eclipse MAT
  • JFR (Java Flight Recorder)

Authoritative references

Primary documentation for this error, worth reading before applying any fix in production.

docs.oracle.com

Related Java errors

See all 19 Java errors →

Browse other categories

Something missing or wrong?

This entry is maintained by hand. If the fix is out of date, incomplete, or you have a better one, email a correction and it will be reviewed.