NoClassDefFoundError

java.lang.NoClassDefFoundError: com/example/MyClass

Quick Answer

A class that was available at compile time is missing at runtime. Check that all required JARs are on the runtime classpath.

Why This Happens

NoClassDefFoundError differs from ClassNotFoundException in that the class was found during compilation but is missing at runtime. This typically indicates a missing dependency JAR, a classpath configuration issue, or a static initializer failure in the class.

The Problem

// Compiled with library.jar but running without it
import com.library.Helper;
Helper.doSomething(); // NoClassDefFoundError at runtime

The Fix

// Ensure library.jar is included in runtime classpath
// Maven: check scope is not 'provided' if needed at runtime
// <dependency>
//   <groupId>com.library</groupId>
//   <artifactId>helper</artifactId>
//   <scope>compile</scope>  <!-- not 'provided' -->
// </dependency>

Step-by-Step Fix

  1. 1

    Identify the missing class

    Read the error message for the class name. The slashes (/) indicate the package path.

  2. 2

    Check runtime dependencies

    Verify that the JAR containing the class is present in the runtime classpath. Check if Maven/Gradle scope is set to 'provided' when it should be 'compile'.

  3. 3

    Check for initialization errors

    If the class exists but its static initializer failed, the root cause is an earlier ExceptionInInitializerError. Check logs for that.

Bugsly catches this automatically

Bugsly's AI analyzes this error pattern in real-time, explains what went wrong in plain English, and suggests the exact fix — before your users even report it.

Try Bugsly free