运行我的第一个 Java 应用程序时出现 InvalidModuleDescriptorException
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/51133398/
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
InvalidModuleDescriptorException when running my first java app
提问by Hainan_dev
I have started learning Java and encountered a problem when trying to run my first program as given below:
我已经开始学习 Java 并在尝试运行我的第一个程序时遇到问题,如下所示:
public class HelloWorld {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("Hello world!");
}
}
On Eclipse Photon I encounter this error when running it:
在 Eclipse Photon 上运行时遇到此错误:
Error occurred during initialization of boot layer
java.lang.module.FindException: Error reading module: C:\Users\Thomas\eclipse-workspace\HelloWorld\bin
Caused by: java.lang.module.InvalidModuleDescriptorException: HelloWorld.class found in top-level directory (unnamed package not allowed in module)
I looked and there is my .class file in bin directory and my .java in the src
directory.
我看了看,bin 目录中有我的 .class 文件,目录中有我的 .javasrc
文件。
Is that normal? How do I fix that?
这是正常的吗?我该如何解决?
回答by Sven Affeld
It seems that you haven't created a package. My usual procedure in Eclipse is:
您似乎还没有创建包。我在 Eclipse 中的通常程序是:
- Create new Java project
- Inside that project: Create a new package
- Inside that package: Create a new Java class
- 创建新的 Java 项目
- 在该项目中:创建一个新包
- 在该包中:创建一个新的 Java 类
Eclipse will help you a lot with the settings. Then just copy your code into that class and hit the 'start' button.
Eclipse 将在设置方面为您提供很多帮助。然后只需将您的代码复制到该类中并点击“开始”按钮。
回答by Naveen Neelam
by removing module class problem solved for me in eclipse
通过删除在 Eclipse 中为我解决的模块类问题
回答by kv vinay
i moved my main class and sample.fxml file to a new package that throws this error below
我将我的主类和 sample.fxml 文件移动到一个新包,该包在下面引发此错误
"Error occurred during initialization of boot layer java.lang.module.FindException: Error reading module: C:\Users\Thomas\eclipse-workspace\HelloWorld\bin Caused by: java.lang.module.InvalidModuleDescriptorException: HelloWorld.class found in top-level directory (unnamed package not allowed in module)"
“启动层java.lang.module.FindException 初始化时出错:读取模块时出错:C:\Users\Thomas\eclipse-workspace\HelloWorld\bin 导致:java.lang.module.InvalidModuleDescriptorException:HelloWorld.class found in顶级目录(模块中不允许使用未命名的包)”
i moved my class file and fxml file to normal position. it fix my problem. but i have to find why it happends. cheers....
我将我的类文件和 fxml 文件移动到正常位置。它解决了我的问题。但我必须找出它发生的原因。干杯....
回答by Jaideep Dhumal
I was getting the same error. Deleting the module-info.javafile solved it for me.
我遇到了同样的错误。删除module-info.java文件为我解决了这个问题。