• Post Reply Bookmark Topic Watch Topic
  • New Topic

Difference between java.lang.ClassNotFoundException and java.lang.NoClassDefFoundError ?  RSS feed

 
kish kumar
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

can anyone explain difference between java.lang.ClassNotFoundException and java.lang.NoClassDefFoundError ?
 
Rob Spoor
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
NoClassDefFoundError is thrown when a class has been compiled with a specific class in the class path but then that class is no longer available during run time. Missing JAR files are the most common reason. As the Javadoc states "The searched-for class definition existed when the currently executing class was compiled, but the definition can no longer be found."

ClassNotFoundException is only thrown when trying to load a class that is not known during compile time using Class.forName or similar techniques and the class does not exist.


So the main difference is, NoClassDefFoundError is for classes known at compile time that are referenced from compiled code, whereas ClassNotFoundException is for classes that are not known at compile time but only at run time.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!