Search code examples
javaintellij-ideajava-moduleopenjfxmodule-info

Error: Main.class found in top-level directory (unnamed package not allowed in module)


Trying to update an application to Java 11 and after sorting through hell with modules I thought I had got rid of all the red errors and now I'm getting this one I've never seen before:

enter image description here

Looking around I've seen people suggest it is possible to do with the application structure:

enter image description here

or the module-info.java file:

enter image description here

Can anybody see what I need to do to get rid of this?

Edit: Error after moving Main.java to a package called 'main' and trying to run it:

enter image description here


Solution

  • In order for a JavaFx to launch your app, it needs access to its main class, so you need to export the package in which the main class is located.

    Add export declaration to module-info:

    module Game.main {
        ...
    
        exports main;
    }