Error “ClassNotFoundException” in IntelliJ IDEA

2019-01-07 14:35发布

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?

9条回答
Juvenile、少年°
2楼-- · 2019-01-07 14:44

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.

查看更多
Root(大扎)
3楼-- · 2019-01-07 14:50

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.

查看更多
女痞
4楼-- · 2019-01-07 14:59

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.

查看更多
Melony?
5楼-- · 2019-01-07 15:00

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

查看更多
Evening l夕情丶
6楼-- · 2019-01-07 15:02

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

查看更多
The star\"
7楼-- · 2019-01-07 15:04

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

查看更多
登录 后发表回答