0
votes

I am trying to compile my Java code.

package Test;
public class HelloWorld {
    public static void main (String args[]) {
        System.out.println("Hello World");
    }
}

I am using Jetbrains IntelliJ IDEA 15. I try to run my sample code and this is the error I get.

/Library/Java/JavaVirtualMachines/jdk1.7.0_17.jdk/Contents/Home/bin/java Exception in thread "main" java.lang.ClassNotFoundException: HelloWorld at java.net.URLClassLoader$1.run(URLClassLoader.java:366) at java.net.URLClassLoader$1.run(URLClassLoader.java:355) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:354) at java.lang.ClassLoader.loadClass(ClassLoader.java:423) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308) at java.lang.ClassLoader.loadClass(ClassLoader.java:356) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:188) at com.intellij.rt.execution.application.AppMain.main(AppMain.java:122)

Process finished with exit code 1

I am not sure what is the problem here. I was trying to search this problem in the internet but the answers I was reading were for running my code through a command line.

2
probably a duplicate. You can copy the snippet into google, and go in to the first result that comes up, which tells you to reset your preferences.hs2345
This a runtime error, not a compile error.user207421

2 Answers

0
votes

If you're creating the run configuration manually, and not using IntelliJ IDEA's support for running a class by clicking the gutter icon next to the main method, you need to specify the correct class name to run, including the package name. For your example, this is "Test.HelloWorld" and not just "HelloWorld".

-1
votes

see the image

click here to see the image

See image and good luck!