Add to Google Reader or Homepage

Exception in thread "main" java.lang.NoClassDefFoundError



  1. This error would occur if you execute the program with a modified classname. consider for eg. Let the name of the program be and if u compile and execute the program as follows
  • javac
  • java example

    2. Whenever a java program is compiled it creates a class file.This class file is used to launch the program.We all know about the variable classpath.The classpath lists all directories and archive files which are all starting points for locating classes.

So when a program is to be executed jvm will look for the class file(of the program) in the path specified in the variable CLASSPATH.

If the class is not available in the path specified by the CLASSPATH variable then this error would appear.



1.This error can be resolved by eliminating the accidental mistyping of the classname during launching.

2.If the CLASSPATH variable is modified to include the class file then this error can be avoided.


  •  The CLASSPATH can be set to multiple values each separated by semi colon as follows                           
java -classpath c:\classdir;.;c:\archives\archive.jar Example.

  • The CLASSPATH can also be made to point to the current location by using the dot(.) as follows.   
  java -classpath .; Example

  • If a class file belongs to a jar then the jar must be added to the CLASSPATH variable.

java errors and exceptions © 2010 | Designed by Chica Blogger | Back to top