What are the reasons for this exception, if the build path is correct and all of the classes are accessible (same package!)? What should I do to try and find the culprit line? Thanks!
-
1checking the stack trace would be a good start – Majid Laissi Apr 11 '13 at 16:26
-
1The only reason for this exception is the class is not present in your classpath.. double check your class path – sanbhat Apr 11 '13 at 16:26
-
1It's because the path is not correct and all of the classes are not accessible. – Hot Licks Apr 11 '13 at 16:29
-
Maybe the answer you are looking for are at the question http://stackoverflow.com/questions/1457863/what-is-the-difference-between-noclassdeffounderror-and-classnotfoundexception?rq=1. Do you use an IDE? – rlinden Apr 11 '13 at 16:35
3 Answers
I would check the directory where all your classes are built. I suspect you will find your class is missing.
EDIT: As @Hot Licks notes, the error you get from a broken class is NoClassDefFoundError
public static void main(String... ignored) {
for (int i = 0; i < 3; i++) {
try {
new BrokenClass();
} catch (Throwable t) {
System.out.println(t);
}
}
}
static class BrokenClass {
static {
if (true)
throw new AssertionError();
}
}
prints on Java 7
java.lang.AssertionError
java.lang.NoClassDefFoundError: Could not initialize class Main$BrokenClass
java.lang.NoClassDefFoundError: Could not initialize class Main$BrokenClass

- 525,659
- 79
- 751
- 1,130
build path is correct and all of the classes are accessible
You should'nt get the error then. The only other reason you can get that error is if the class was loaded by a child class loader and was in the classpath, but a parent class loader is trying to access it (assuming the delegation model is parent-first). In that case the class is loaded by the JVM but the program cannot access it.
Come to think of it, there are some more complicated scenarios that can lead to class loading exceptions based on how classloaders are instantiated and used. Commons logging suffered from these and I've been on the receiving end more times than I'd like to admit. There is an excellent article that highlights these scenarios if you'd like to take a look.

- 11,095
- 2
- 38
- 49
Here's a good article that might just help you. It lists down 13 things you can consider looking at to find that culprit.

- 22,535
- 13
- 46
- 63