How to fix InvalidModuleDescriptorException

Introduction

The exception java.lang.module.InvalidModuleDescriptorException is caused by unnamed package not allowed in a module. Check the JDK version of the project.

Error

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

 

InvalidModuleDescriptorException

Fix

Unnamed package is not allowed in the module with latest JDK. We will get this error if the project is allowed for modules by creating module-info.java during the project creation phase.

To avoid this kind of exception, move all the classes that are in default package to some named packages.

Create a Package

Refactor the code to move the classes in unnamed packages to named ones.

 

Java Exception Fix