Skip to content

Fix "NoClassDefFoundError: Could not initialize class" in a mod

java.lang.NoClassDefFoundError: Could not initialize class com.example.examplemod.ModItems means the class’s setup failed earlier, even though the name sounds like a missing class: a static field or static { } block threw an exception the first time the class was used. Java then marks the class as broken, and every later use fails with this message.

The first failure is logged as java.lang.ExceptionInInitializerError. Search the log for it, above the Could not initialize class line. The Caused by: line under it is the real error, and the first frame in your own package shows the line.

On a NeoForge 1.21.1 server, a mod whose static field read past the end of an empty array logged this the first time the class was used:

java.lang.ExceptionInInitializerError: null
at com.example.examplemod.ExampleMod.<init>(ExampleMod.java:25)
Caused by: java.lang.ArrayIndexOutOfBoundsException: Index 0 out of bounds for length 0
at com.example.examplemod.Boom.<clinit>(Boom.java:5)

and this the second time:

java.lang.NoClassDefFoundError: Could not initialize class com.example.examplemod.Boom
at com.example.examplemod.ExampleMod.<init>(ExampleMod.java:29)
Caused by: java.lang.ExceptionInInitializerError: Exception java.lang.ArrayIndexOutOfBoundsException: Index 0 out of bounds for length 0 [in thread "modloading-worker-0"]

Current Java 17 and 21 releases repeat the first error in the later one’s Caused by: line, so the cause is there even when the earlier lines are gone. If your log has no such line, search it from the start, or run again and watch it.

Checked on 19 November 2026 on a NeoForge 1.21.1 server on Java 21, and the Caused by: line on Java 17.0.19 and 21.0.11. The logs above are shortened.

  • A static field that needs something not ready yet, such as building a block, item or entity before the registries are open, or reading a config value before the config is loaded.
  • Client classes on a server. A static field that touches a client-only class (anything under net.minecraft.client) fails on a dedicated server. Keep client code in client-only classes.
  • An exception in your own setup code, such as a NullPointerException or a bad array index in a static block.

Once the Caused by: error is fixed, Could not initialize class goes away with it.

Crash Doctor in Linen reads the crash report and the log next to it, then names the mod, the line and what to change. It’s free. It looks past follow-on errors like this one for the first failure. Fix ClassNotFound and NoSuchMethod errors covers classes that really are missing.