7

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

Naman
  • 27,789
  • 26
  • 218
  • 353
AlwaysNeedingHelp
  • 1,851
  • 3
  • 21
  • 29
  • 4
    Your Main class isn't in any package (or to be precise, it uses unnamed package), and that's not allowed in modular app. Add package declaration to Main.java (e.g. "package main;"). – Guest 21 Sep 23 '18 at 20:29
  • @Guest21 I get an error "Package main does not correspond to the file path" – AlwaysNeedingHelp Sep 23 '18 at 20:31
  • IDE should offer you to move the file - put mouse cursor on package name, hit Alt+Enter, and click on "Move to package main". Or move the file manually - make new package "main" and move the file into it. – Guest 21 Sep 23 '18 at 20:36
  • @Guest21 thanks, I created a new package called main and moved it in, I got a new error which again has me confused, mind taking a look? I put it in the OP. – AlwaysNeedingHelp Sep 23 '18 at 20:39

3 Answers3

7

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;
}
Guest 21
  • 672
  • 1
  • 6
  • 10
0

If your class is under (default package) :

Unrelated to the specific question.

You could encounter this error while trying to run a class for example HelloWorld.java inside the package (default package).

To solve the issue create a new package under the src folder (at least in a generic case) and give it a name then move your class into the new package and try running it again:

Right-lick on the class (under the named package) -> Run As -> Java Application.

Marco D.G.
  • 2,317
  • 17
  • 31
-2

If you move a class to a different folder, before the class declaration line, you need to have a reference to the folder where this class is/should be located - telling the system where to look. For example:

//This line below is important
package main.java.main.Main;

public class Main extends Application {

    @Override
    public void start(Stage primaryStage) throws Exception {
    }
}
NL23codes
  • 1,181
  • 1
  • 14
  • 31