Error "ClassNotFoundException" in IntelliJ IDEA

JavaIntellij Idea

Java Problem Overview


I made this simple program:

package main.java;

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

And got this error. I have NO idea what is happening,

"C:\Program Files\Java\jdk1.7.0_21\bin\java" -Didea.launcher.port=7532 "-Didea.launcher.bin.path=C:\Program Files (x86)\JetBrains\IntelliJ IDEA Community Edition 12.1.4\bin" -Dfile.encoding=UTF-8 -classpath "C:\Program Files\Java\jdk1.7.0_21\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.7.0_21\jre\lib\deploy.jar;C:\Program Files\Java\jdk1.7.0_21\jre\lib\javaws.jar;C:\Program Files\Java\jdk1.7.0_21\jre\lib\jce.jar;C:\Program Files\Java\jdk1.7.0_21\jre\lib\jfr.jar;C:\Program Files\Java\jdk1.7.0_21\jre\lib\jfxrt.jar;C:\Program Files\Java\jdk1.7.0_21\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.7.0_21\jre\lib\management-agent.jar;C:\Program Files\Java\jdk1.7.0_21\jre\lib\plugin.jar;C:\Program Files\Java\jdk1.7.0_21\jre\lib\resources.jar;C:\Program Files\Java\jdk1.7.0_21\jre\lib\rt.jar;C:\Program Files\Java\jdk1.7.0_21\jre\lib\ext\access-bridge-64.jar;C:\Program Files\Java\jdk1.7.0_21\jre\lib\ext\dnsns.jar;C:\Program Files\Java\jdk1.7.0_21\jre\lib\ext\jaccess.jar;C:\Program Files\Java\jdk1.7.0_21\jre\lib\ext\localedata.jar;C:\Program Files\Java\jdk1.7.0_21\jre\lib\ext\sunec.jar;C:\Program Files\Java\jdk1.7.0_21\jre\lib\ext\sunjce_provider.jar;C:\Program Files\Java\jdk1.7.0_21\jre\lib\ext\sunmscapi.jar;C:\Program Files\Java\jdk1.7.0_21\jre\lib\ext\zipfs.jar;C:\Users\Tim\IdeaProjects\Rust\out\production\Rust;C:\Program Files (x86)\JetBrains\IntelliJ IDEA Community Edition 12.1.4\lib\idea_rt.jar" com.intellij.rt.execution.application.AppMain java.start
Exception in thread "main" java.lang.ClassNotFoundException: java.start
	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:113)

Process finished with exit code 1

Anyone know what is wrong?

Java Solutions


Solution 1 - Java

Probably your project structure was src/main/java/start.java but when you added it to IntelliJ you have set src as a source folder, so IntelliJ put main.java as a package.

In Project Setting (Ctrl+Shift+Alt+S) → Modules → Sources tab set src/main/java as Source Folder. Then in your simple program change package to whatever you like (e.g. my.test). After that if IntelliJ reports any error in line with package quick fix with Alt+Enter should help

Solution 2 - Java

I had this problem and couldn't solve it with any of these solutions. However I think the problem was that I was using 'open' to create a project from a directory with some java files in. Instead I had to 'create new project' with the same directory as root.

Make sure you delete any '.idea' directories and '.iml' files when 'create new project' since it will otherwise complain about a project already being in the given directory.

Solution 3 - Java

Above answers are fine. I would like to add an one more option if someone has any dependency with scope as provided then following configuration is needed.

Run -> Edit Configurations -> Include dependencies with "Provided" scope.

Mark the tick box, apply and run.

Solution 4 - Java

As mentioned before you should check File → ProjectStructure → ProjectSettings → Modules → Sources - your folder must be marked as a "Source". Also you should update your Run → EditConfigurations → Configuration → Main class to correspond with your package

Solution 5 - Java

In my case the path to the project had some characters such as : \ /

ex: C:\something\other:thing\aaa\project , and that's why it didn't worked. Moving the project to a path that doesn't have those characters fixed the errors.

Solution 6 - Java

Just for the future: I had unicode characters in the folder name like "Course name"/Tehtävät/Project and the problem was in "ä". When i changed it to "a" the program started to work.

Solution 7 - Java

For me, in IntelliJ-Idea 2016, the problem was that in Project_structure/modules, in the Path tab you have to check "Inherit project compile output path", rather than "Use module compile output path"

Solution 8 - Java

I falled down this problem after a recent re install of my intellif community edition.

IntelliJ IDEA 2016.3.2 Build #IC-163.10154.41, built on December 21, 2016 JRE: 1.8.0_112-release-408-b6 amd64 JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o om my laptop asus N73SV with Ubuntu 16.04

The Context is: I was trying to restart Intellij projects previously running fine. That projects where done with intellij CI, AND THEY WHERE located on my freebox server.

I've tryed all solutions proposed here, but without result. At the end I just: Close the project. Shutdown Intellij. copy / paste the entire project from my freebox server to my system folder. Re start Intellij, open the project previously paste into my system folder. Rebuild the projet from the /Build/Re build menu. And finaly Run my project. And !!! DONE...It works!!

My suggest is: Is there a problem with pathname lenght or characters contented in that pathname to the project. Indeed /run/user/1000/gvfs/smb-share:server=freebox,share=disque%20dur/blaBlaToMyFileProjectFolder The full pathname contents 127 caracters among :,-_/%=

It that the tric?

Hope it's help. Sorry for my broken english. I'm french ;-) Oliver

Solution 9 - Java

I also had same problem but I couldn't find solution on web so tried rectifying myself, after reading so many blogs i understood the concept, In my case everything was fine as I have download code from git but my IDE intellij couldn't recognise maven dependencies and that's why intellij was throwing this error, my pom.xml was having all dependencies but still intellij couldn't able to recognise it. I navigated to maven window at right in intellij and added path of the project in which I was working after adding it maven loaded all the dependencies and my code worked fine.So basically only three steps can make you resolve it:

  1. Open maven window in intellij.
  2. Click "+" and add path where your prjojects pom.xml file is present.
  3. Click Enter. Now you can run your project. Happy coding!!

Solution 10 - Java

Check the scope of the dependency from which the class which is shown in error stack is derived. In my case, the scope was given as provided, when I removed the scope, it worked.

Solution 11 - Java

I've got this error when i updated Intellij Idea to 2019.3 and couldn't solve it with any of these solutions. But it solved when i uncheck all profiles in maven window and check proper profile again.

Solution 12 - Java

Your package is main.java, you pass the argument com.intellij.rt.execution.application.AppMain java.start, and you exception says that that can not found java.start. And this is correct.

Try to compile it using only console. Leave the IDE for the beginning, invest you time to understand the compiler not how the IDE works.

Solution 13 - Java

Rebuild the project. It's that easy. Don't thank

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAidoView Question on Stackoverflow
Solution 1 - JavaMateusz D.View Answer on Stackoverflow
Solution 2 - JavaTrionetView Answer on Stackoverflow
Solution 3 - JavasujithramanathanView Answer on Stackoverflow
Solution 4 - Javaa.parfenovView Answer on Stackoverflow
Solution 5 - JavaBoldijar PaulView Answer on Stackoverflow
Solution 6 - JavaTomTView Answer on Stackoverflow
Solution 7 - JavaGuillaume LebretonView Answer on Stackoverflow
Solution 8 - JavamariotazView Answer on Stackoverflow
Solution 9 - JavaPrateek shrivastavaView Answer on Stackoverflow
Solution 10 - JavaRimjhim DoshiView Answer on Stackoverflow
Solution 11 - JavaÇağdaş TuncaView Answer on Stackoverflow
Solution 12 - JavaDamian Leszczyński - VashView Answer on Stackoverflow
Solution 13 - JavaTalView Answer on Stackoverflow