Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exception in thread "main" java.lang.ClassNotFoundException:

I recently installed intellij IDEA 14.0 and to make sure everything was working I created a simple Hello World program. I do not understand why the output is not correct and why I am getting this error. If someone could please help that would be great.

This is the program:

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

This is the error:

Exception in thread "main" java.lang.ClassNotFoundException: Hello
at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:260)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:116)
like image 254
kayanushpatel Avatar asked Jan 10 '15 00:01

kayanushpatel


People also ask

How do I fix exception in thread main Java Lang NullPointerException?

In Java, the java. lang. NullPointerException is thrown when a reference variable is accessed (or de-referenced) and is not pointing to any object. This error can be resolved by using a try-catch block or an if-else condition to check if a reference variable is null before dereferencing it.

What is exception in thread main Java Lang IllegalStateException?

An IllegalStateException is a runtime exception in Java that is thrown to indicate that a method has been invoked at the wrong time. This exception is used to signal that a method is called at an illegal or inappropriate time.

How do I fix NoClassDefFoundError?

You can fix NoClassDefFoundError error by checking following: Check the exception stack trace to know exactly which class throw the error and which is the class not found by java.


2 Answers

The reason you're getting this error is because you didn't save the class into a file called Hello.java (case-sensitive!)

like image 196
Nir Alfasi Avatar answered Sep 27 '22 22:09

Nir Alfasi


This is just problem of intellij IDE.

Solution Steps:

  1. CtrlShiftAlts -> Preject Setting -> modules tab -> expand <project_name> and go to <project_name>_main
  2. refer Image: SS1
  3. In Sources tab -> ** click on x symbol**

SS2

  1. click YES
  2. Right click on SS4 -> sources
  3. Apply and OK

Finally build your project.

SS7

Enjoy.

like image 29
ankit Avatar answered Sep 28 '22 00:09

ankit