exception in thread main java.lang.NoClassDefFoundError:

exception in thread main java.lang.NoClassDefFoundError:

I found one another common reason. If you create the java file inside a package using IDE like eclipse, you will find the package name on the top of your java file like package pkgName. If you try to run this file from command prompt, you will get the NoClassDefFoundError error. Remove the package name from the java file and use the commands in the command prompt. Wasted 3 hours for this. — Abhi

Exception in thread main java.lang.NoClassDefFoundError  

One of the places java tries to find your .class file is your current directory. So if your .class file is in C:java, you should change your current directory to that.

To change your directory, type the following command at the prompt and press Enter:

cd c:java  

This . tells java that your classpath is your local directory.

Executing your program using this command should correct the problem:
java -classpath . HelloWorld  

exception in thread main java.lang.NoClassDefFoundError:

If your package is helloworld you would go to parent dir of your package then run:

java helloworld.HelloWorld

Leave a Reply

Your email address will not be published.