The following program is throwing error:
public class HelloWorld {
public static void main(String args[]) {
System.out.println(\"Hello World!\");
if your Program.java is in "src/mypkg/subpkg/" directory:
go to "src" dir
Then to compile use "javac mypkg/subpkg/Program.java"
To run use "java mypkg.subpkg.Program.class"
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
I had the same problem, and stumbled onto a solution with 'Build Main Project F11'. The ide brought up an "option" that I might want to uncheck 'Compile on Save' in the Build > Compiling portion of the Project configuration dialog. Unchecking 'Complile on Save' and then doing the usual (for me) 'Clean and Build' did the trick for me.
I had this proplem I used maven. I just click maven projects ant then name
project-> plugins -> clean -> and button run
.
I had this error because I had my files within a package. So my foo package I had to call like:
java foo.HelloWorld