i am new to java and i just made my first program: HelloWorld and after i compiled it I tried to run it and it gave me this error:
Exception in thread “main” java.lang.NoClassDefFoundError: HelloWorld
Caused by: java.lang.ClassNotFoundException: HelloWorld at
java.net.URLClassLoader$1.run(URLClassLoader.java:217) at
java.security.AccessController.doPrivileged(Native Method) at
java.net.URLClassLoader.findClass(URLClassLoader.java:205) at
java.lang.ClassLoader.loadClass(ClassLoader.java:321) at
sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294) at
java.lang.ClassLoader.loadClass(ClassLoader.java:266) Could not find
the main class: HelloWorld. Program will exit.
I am using ubuntu version 10.04, I made the program with geany, and compiled it in terminal by using the command javac HelloWorld.java.
Then i ran it in terminal with the command: java HelloWorld and then had the error above.
my HelloWorld.java file looks like this:
public class HelloWorld {
public static void main (String[] args) {
System.out.println("Hello World");
}
}
then my HelloWorld.class file looks like this:
public static void main(string[] args)
You either need to run your java command directly from the directory that contains your .class file, or you need define the classpath, that is, the place where the JVM can find your compiled Java class. Try:
where
<directory>is the (relative) path to the directory containing your HelloWorld.class file.