1

So I recently installed eclipse on my win10 PC, and I created a public class. This is the code:

package comex;

public class MyClass { public static void main(String[] args) { // TODO auto-generated method stub
System.out.println("Hello World!") } }

Next, an error showed:

Error occurred during initialization of boot layer java.lang.module.FindException: Error reading module: C:\Users\Ioana Predi\eclipse-workspace\Project1\bin Caused by: java.lang.module.InvalidModuleDescriptorException: MyClass.class found in top-level directory (unnamed package not allowed in module)

Then, I deleted the info.java file and the following error has showed:

Exception in thread "main" java.lang.Error: Unresolved compilation problem:
   at MyClass.main(MyClass.java:6)

What can I do to fix this?

Anonymus
  • 131
  • 4

1 Answers1

0

MyClass should be moved to the package comex. Create a directory comex in your source directory and move the class into it.

It also appears that you are using the MODULEPATH rather than the class path. This is already described in this answer.

John Mercier
  • 1,637
  • 3
  • 20
  • 44
  • How do I create that directory? Baby steps, please? – Anonymus Nov 12 '20 at 17:30
  • Also, I didn't find any jar files in MODULEPATH expansion. – Anonymus Nov 12 '20 at 17:35
  • Where to create the directory largely depends on your build setup. Wherever your source dir is located you should be able to right click and create a new directory. For the module path did you check the eclipse settings? – John Mercier Nov 12 '20 at 17:40
  • One thing you might try is not to use eclipse but simply go to the directory where the source file is located and type `java MyClass.java`. If you are using java 11+ it should run the single source file. – John Mercier Nov 12 '20 at 17:41
  • Your welcome! If this works can you accept the answer? – John Mercier Nov 12 '20 at 17:42