NetBeans 12.0:“类没有主方法"(但确实如此) [英] NetBeans 12.0: "Class does not have a main method" (but it does)

查看:93
本文介绍了NetBeans 12.0:“类没有主方法"(但确实如此)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

NetBeans 12.0

NetBeans 12.0

Jdk 15

我无法启动我的程序,单击绿色运行按钮没有任何作用,并且在 MainFrame 上右键单击 + 运行文件会出现错误类没有主方法".但正如你在下面的 GIF 中看到的,它确实有一个 main(String args[]).

I cannot launch my program, clicking the green run button doesn't do anything, and right click + run file on MainFrame gives the error "Class does not have a main method". But as you can see in the GIF below, it does have a main(String args[]).

有人知道为什么会这样吗?

Does anyone have any idea why this happens?

推荐答案

初步建议:

  1. 确保首先保存所有文件.如果您尝试运行包含 main 方法的类尚未保存的程序,则可能会发生这种情况.

  1. Make sure all files are saved first. If you try to run a program where the class containing the main method has not been saved, this can happen.

右键单击项目名称(在项目资源管理器中),然后选择属性 >运行 - 然后确保在那里选择了主类.同样,如果您没有保存文件,NetBeans 可能无法找到 main 方法(目前).

Right-click on the project name (in the Projects explorer), then select Properties > Run - and then make sure the main class is selected there. Again, if you have not saved the files NetBeans may not be able to find the main method (yet).

检查您的项目中是否还有其他类也有 public static void main(String args[]) 方法也是值得的.

It may also be worth checking whether you have any other classes in your project which also have a public static void main(String args[]) method.

如果一切都失败了:

清除 NetBeans 缓存可能会有所帮助.

Clearing the NetBeans cache may help.

转到帮助 >关于,并记下缓存目录的位置.从 NetBeans 退出.删除缓存目录.重新启动 NetBeans.

Go to Help > About, and note the location of the cache directory. Exit from NetBeans. Delete the Cache directory. Restart NetBeans.

请注意@skomisa 在评论中指出的内容:

Please note what @skomisa points out in the comments:

NetBeans 12.0 不支持 Java 15,虽然它可能适用于一个微不足道的项目,但仍然存在问题(如此处的评论所示).将这种组合用于生产代码是鲁莽的,IDE(而不是编译器)可能无法正确处理 Java 15 中的新功能.

这篇关于NetBeans 12.0:“类没有主方法"(但确实如此)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆