线程“main”中的异常 java.lang.ClassNotFoundException:

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27871379/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 05:11:43  来源:igfitidea点击:

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

javaintellij-ideaintellij-14

提问by kayanushpatel

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.

我最近安装了 intellij IDEA 14.0 并确保一切正常,我创建了一个简单的 Hello World 程序。我不明白为什么输出不正确以及为什么我会收到此错误。如果有人可以请帮助那就太好了。

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.run(URLClassLoader.java:372)
at java.net.URLClassLoader.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)

回答by alfasin

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

您收到此错误的原因是您没有将类保存到名为Hello.java(区分大小写!)的文件中

回答by ankit

This is just problem of intellij IDE.

这只是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**
  1. CtrlShiftAlts->项目设置->模块选项卡->展开<project_name>并转到<project_name>_main
  2. 参考图片: SS1
  3. 在 Sources 选项卡中-> ** 点击 x 符号**

SS2

SS2

  1. click YES
  2. Right click on SS4-> sources
  3. Apply and OK
  1. 单击是
  2. 右键单击SS4->来源
  3. 申请并确定

Finally build your project.

最后构建你的项目。

SS7

SS7

Enjoy.

享受。

回答by dmarquina

It usually happens with IntelliJ.

它通常发生在 IntelliJ 上。

I solved it deleting all modules and only leaving which have more hierarchy

我解决了它删除所有模块并只留下具有更多层次结构的模块

The other modules(like main or test) are already part of product

其他模块(如 main 或 test)已经是产品的一部分