错误:在顶级目录中找到Main.class(模块中不允许使用未命名的程序包) [英] Error: Main.class found in top-level directory (unnamed package not allowed in module)

查看:214
本文介绍了错误:在顶级目录中找到Main.class(模块中不允许使用未命名的程序包)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试将应用程序更新为Java 11,并在使用模块对地狱进行排序之后,我以为我摆脱了所有红色错误,现在我得到了一个我从未见过的错误:

Trying to update an application to Java 11 and after sorting through hell with modules I thought I had got rid of all the red errors and now I'm getting this one I've never seen before:

环顾四周,我发现人们建议可以使用应用程序结构:

Looking around I've seen people suggest it is possible to do with the application structure:

或module-info.java文件:

or the module-info.java file:

有人可以看到我需要做些什么来摆脱这种情况吗?

Can anybody see what I need to do to get rid of this?

将Main.java移至名为"main"的程序包并尝试运行它后发生错误:

Error after moving Main.java to a package called 'main' and trying to run it:

推荐答案

为了使JavaFx启动您的应用程序,它需要访问其主类,因此您需要导出主类所在的包.

In order for a JavaFx to launch your app, it needs access to its main class, so you need to export the package in which the main class is located.

将导出声明添加到module-info:

Add export declaration to module-info:

module Game.main {
    ...

    exports main;
}

这篇关于错误:在顶级目录中找到Main.class(模块中不允许使用未命名的程序包)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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