Java 必须声明一个命名包 eclipse 因为这个编译单元与命名模块相关联

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/53033899/
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 00:41:50  来源:igfitidea点击:

must declare a named package eclipse because this compilation unit is associated to the named module

javaerror-handling

提问by J. Doe

I just downloaded eclipse for Java Yesterday but when I was trying to get make my first program, I kept on getting this error:

我昨天刚刚下载了 Java 的 eclipse,但是当我尝试制作我的第一个程序时,我不断收到此错误:

must declare a named package eclipse because this compilation unit is associated to the named module x. 

How do I fix this?

我该如何解决?

采纳答案by Danh Tran

Just delete module-info.javaat your Project Explorer tab.

只需在您的项目资源管理器选项卡中删除module-info.java 即可

回答by reben

The "delete module-info.java at your Project Explorer tab" answer is the easiest and most straightforward answer, but

“在项目资源管理器选项卡中删除 module-info.java”答案是最简单、最直接的答案,但是

for those who would want a littlemore understanding or control of what's happening, the following alternate methods may be desirable;

对于那些谁愿意一点点更多的了解或发生了什么,下面的替代方法可能需要控制;

  • make an ever so slightly more realistic application; com.YourCompany.etc or just com.HelloWorld (Project name: com.HelloWorld and class name: HelloWorld)
  • 制作一个更加逼真的应用程序;com.YourCompany.etc 或 com.HelloWorld(项目名称:com.HelloWorld 和类名称:HelloWorld)

or

或者

  • when creating the java project; when in the Create Java Project dialog, don't choose Finish but Next, and deselect Create module-info.java file
  • 创建java项目时;在 Create Java Project 对话框中时,不要选择 Finish 而是 Next,并取消选择 Create module-info.java file