Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

InvalidModuleDescriptorException when running my first java app

I have started learning Java and encountered a problem when trying to run my first program as given below:

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:

 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.

Is that normal? How do I fix that?

like image 646
Hainan_dev Avatar asked Jul 02 '18 09:07

Hainan_dev


2 Answers

I was getting the same error. Deleting the module-info.java file solved it for me.

like image 74
Jaideep Dhumal Avatar answered Sep 24 '22 00:09

Jaideep Dhumal


It seems that you haven't created a package. My usual procedure in Eclipse is:

  • Create a new Java project
  • Inside that project: Create a new package
  • Inside that package: Create a new Java class

Eclipse will help you a lot with the settings. Then just copy your code into that class and hit the 'start' button.

like image 24
Sven Affeld Avatar answered Sep 21 '22 00:09

Sven Affeld