Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.4k views
in Technique[技术] by (71.8m points)

java - 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

question from:https://stackoverflow.com/questions/65900553/i-wish-to-import-data-from-mysql-into-a-jtable-and-i-have-used-the-rs2xml-jar-bu

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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;
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...