B.Sarkar
B.Sarkar

Reputation: 167

Error occurred during initialization of boot layer

I followed the steps to create the HelloWorld example but it doesn't run. It gives the following error:

Error occurred during initialization of boot layer java.lang.module.FindException: Error reading module: F:\Develop\eclipse\HelloWorld\bin Caused by: java.lang.module.InvalidModuleDescriptorException: HelloWorld.class found in top-level directory (unnamed package not allowed in module)"

enter image description here Please advise how to solve this.

Upvotes: 16

Views: 73980

Answers (5)

Vijay Keshri
Vijay Keshri

Reputation: 507

There are two ways to fix this:

  1. Remove the module-info.java file (if not needed):

If you don't intend your project to be a module, you can simply remove the module-info.java file from your project. This disables the modular project structure and allows classes outside of packages.

  1. Create a package and move the class (if using modules):

If you want to keep the modular project structure, you need to create a package and move the Hello.class file inside it. Here's how: In your project directory, create a new folder for your package. For example, you could create a folder named com.example. Move the Hello.class file inside the newly created package folder. (Optional) Edit your Hello.class file to add the package declaration at the beginning of the file. For example:

package com.example;

public class Hello {
  // ... your class code
}

Choosing the right solution depends on whether you want your project to be modular or not.

Upvotes: 0

Tushar Rao
Tushar Rao

Reputation: 39

Just Delete module-info.java from project and its solves the issue.

Upvotes: 2

Parameshwar
Parameshwar

Reputation: 966

I had similar issue, the problem i faced was i added the selenium-server-standalone-3.141.59.jar under modulepath instead it should be under classpath

so select classpath via (project -> Properties -> Java Bbuild Path -> Libraries) add the downloaded latest jar

After adding it must be something like this

enter image description here

And an appropriate driver for browser has to be downloaded for me i checked and downloaded the same version of chrome for chrome driver and added in the C:\Program Files\Java

And following is the code that worked fine for me

    public class TestuiAautomation {

        public static void main(String[] args) {

            System.out.println("Jai Ganesha");
            try {
                System.setProperty("webdriver.chrome.driver", "C:\\Program Files\\Java\\chromedriver.exe");
                System.out.println(System.getProperty("webdriver.chrome.driver"));
                ChromeOptions chromeOptions = new ChromeOptions();
                chromeOptions.addArguments("no-sandbox");
                chromeOptions.addArguments("--test-type");
                chromeOptions.addArguments("disable-extensions");
                chromeOptions.addArguments("--start-maximized");
                WebDriver driver = new ChromeDriver(chromeOptions);
                driver.get("https://www.google.com");
                System.out.println("Google is selected");
            } catch (Exception e) {
                System.err.println(e);
            }

        }

    }

For reference

Upvotes: 0

Shinoy p b
Shinoy p b

Reputation: 393

The error occurs because of you add your jar library files to MODULEPATH instead of CLASSPATH. You have to add jar files to your CLASSPATH. If you already add jar files to MODLEPATH you have to remove from there and add jar files to CLASSPATH, there is the steps:

1] Right click on your project name in ECLIPSE IDE

2] Click on PROPERTIES -> JAVA BUILD PATH -> click LIBRARY tab .The you get the window like this:

Java build path window

3] Expand MODULEPATH and select all jar files and remove it :look the picture below:

Modulepath jar file removing

4] After that click on CLASSPATH ->and click the button 'ADDJAR' and select the jar files ,your are done. Look the picture below for clarification;

Add jar to classpaht

5] After adding jars files in CLASSPATH it looks like this:

After adding jar file to classpath

Upvotes: 16

Yueyi
Yueyi

Reputation: 51

I had the same error before because I use the default package.

And I solved the problem in this way: Right-click the project - Properties - Java Build Path - move the class from Modulepath to Classpath

And it worked!

Upvotes: 5

Related Questions