Showing posts with label ClassNotFoundException. Show all posts
Showing posts with label ClassNotFoundException. Show all posts

Friday, 31 October 2014

What is difference between ClassNotFoundException and NoClassDefFoundError?


 A ClassNotFoundException is thrown when the reported class is not found by the ClassLoader in the CLASSPATH. It could also mean that the class in question is trying to be loaded from another class which was loaded in a parent classloader and hence the class from the child classloader is not visible.
Consider if NoClassDefFoundError occurs which is something like
java.lang.NoClassDefFoundError
src/com/ClassA
does not mean that the ClassA  class is not in the "CLASSPATH". 
It means that the class ClassA was found by the ClassLoader however when trying to load the class, it ran into an error reading the class definition. 
This typically happens when the class in question has static blocks or members which use a Class that's not found by the ClassLoader. 
So to find the culprit, view the source of the class in question (TestClass in this case) and look for code using static blocks or static members