Wednesday, October 21, 2009

Difference between NoClassDefFoundError and ClassNotFoundException

http://java.sun.com/j2se/1.5.0/docs/api/java/lang/NoClassDefFoundError.html

"The searched-for class definition existed when the currently executing class was compiled, but the definition can no longer be found. "


http://java.sun.com/j2se/1.5.0/docs/api/java/lang/ClassNotFoundException.html

"but no definition for the class with the specified name could be found. "


The explanation given by the javadocs is very misleading.
In reality, NoClassDefFoundError is thrown when the class CAN be found, but there was an exception in the static initializers. The naming strategy chosen by Sun is VERY misleading... one tries to fix the classpath, while the problem is in the class definition itself.

No comments: