简体   繁体   English

在Mac上的IntelliJide中出现错误“找不到类”

[英]Error “class not found” in IntelliJ ide on mac

I am currently running the latest IntelliJ on mac os el capitan. 我目前正在mac os el capitan上运行最新的IntelliJ。

I have built a project and it builds successfully, however when I try to run it I get the following message: 我已经构建了一个项目,并且构建成功,但是当我尝试运行它时,出现以下消息:

    Exception in thread "main" java.lang.ClassNotFoundException: com.company.Main
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:123)

 Process finished with exit code 1

I have looked at this question Error "ClassNotFoundException" in IntelliJ IDEA however none of the answers there worked. 我已经在IntelliJ IDEA中查看了此问题“ ClassNotFoundException”错误,但是那里的答案都无效。

Any Ideas? 有任何想法吗?

You might not know it, but when you run your program from within IntelliJ IDEA, you are making use of a Run/Debug Configuration to do that. 您可能不知道,但是从IntelliJ IDEA中运行程序时,您正在使用“运行/调试配置”来执行此操作。 IntelliJ IDEA keeps important information about how to run your program in these Run/Debug Configurations. IntelliJ IDEA在这些“运行/调试配置”中保留了有关如何运行程序的重要信息。 If your program does not start, it is most likely due to a Run/Debug Configuration misconfiguration. 如果您的程序没有启动,则很可能是由于“运行/调试配置”配置错误。

Edit your Run/Debug Configurations, find the Run/Debug Configuration that you are currently using, and look at the "Main class:" field. 编辑您的运行/调试配置,找到您当前正在使用的运行/调试配置,然后查看“主类:”字段。 You will find that it is "com.company.SomeClass". 您会发现它是“ com.company.SomeClass”。 Replace that with the full name of your main class. 将其替换为您的主类的全名。 Your main class is the class with your main() function. 您的主类是具有main()函数的类。

Alternatively, find the class that contains your main() function, open up a context menu on that class, and select 'Run' or 'Debug'. 或者,找到包含main()函数的类,在该类上打开一个上下文菜单,然后选择“运行”或“调试”。 This will create a new Run/Debug configuration for it. 这将为其创建一个新的运行/调试配置。

If the newly created Run/Debug configuration is not working, open up the Run/Debug Configuration Dialog and compare your newly created Run/Debug configuration against the old one, there may be some additional setting that needs to be copied from the old to the new. 如果新创建的“运行/调试”配置不起作用,请打开“运行/调试配置”对话框,然后将新创建的“运行/调试”配置与旧配置进行比较,可能需要将一些其他设置从旧配置复制到新。

The Run/Debug Configuration Dialog can be found by selecting "Edit configurations..." from the Run/Debug Configuration Drop Down List. 通过从“运行/调试配置”下拉列表中选择“编辑配置...”,可以找到“运行/调试配置”对话框。

The Run/Debug Configuration Drop Down List can be found on the main toolbar of IntelliJ IDEA. 可以在IntelliJ IDEA的主工具栏上找到“运行/调试配置”下拉列表。 (Normally, it is the only drop-down list on the toolbar.) (通常,它是工具栏上唯一的下拉列表。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM