Class NotFoundException in IntelliJ IDEA

I got an IntelliJ project from someone else, but it will not run even the simplest classes for me.

As a quick example, the following class will throw a ClassNotFoundException without compiler errors:

 package myPackage; public class Main { public static void main(String[] args) { System.out.println("Hello World!"); System.out.println("Soon our GUI will start from here!"); System.exit(0); } } 

This will cause the following error:

 Exception in thread "main" java.lang.ClassNotFoundException: myPackage.Main 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) Process finished with exit code 1 

The file structure is as follows: <git root> / src / myPackage / Main.java

I set the 'src' folder as the 'source folder'. There are no compiler errors in my application. I canceled the caches several times, but without any effect. In my module settings, my module dependencies contain <Module source> and jdk 1.8.

I cannot find the answer here (google) anywhere, and it seems to me that this error is related to the way IntelliJ handles the project. When I first pulled out the project, the src folder was NOT set as the source folder, which probably means that I can miss other settings as well.

+5
source share
1 answer

Zach Newsham's suggestion helped me. Here is what I did:

  • Remote .iml file
  • File> New> Project, specify the existing folder with the code
  • project setup completed (manifest, artifacts).

Now the project is in progress.

Of course, there may be other reasons for ClassNotFound . However, when everything looks normal or an error occurs after it worked before, try these simple steps.

+1
source

Source: https://habr.com/ru/post/1208006/


All Articles