3

I started a new JavaFX application with the JavaFX project template that IntelliJ gives you that will only display a GUI created with Scene Builder with some line charts, as far as I'm concerned, the code is right and simple, it's just a test project.

Also, I can't visualize the .class file in IntelliJ

The message is:

Error occurred during initialization of boot layer
java.lang.module.FindException: Error reading module: C:\Users\pv3\Desktop\PruebasFX_OracleFXProyectInicio\target\classes
Caused by: java.lang.module.InvalidModuleDescriptorException: GraficasVentPrueba1.class found in top-level directory (unnamed package not allowed in module)
    
Process finished with exit code 1

My code:

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.stage.Stage;
import java.io.IOException;


public class GraficasVentPrueba1 extends Application {

    @Override
    public void start(Stage stage) throws IOException{
        FXMLLoader launcherGraficas = new FXMLLoader(GraficasVentPrueba1.class.getResource("GraficasVentPrueba1.fxml"));
        Scene emergenteGraficas = new Scene(launcherGraficas.load());
        stage.setScene(emergenteGraficas);
        stage.show();
    }
    public static void main(String[] args) {
        launch(args);
    }
}

It supposed to just open the .fxml. Instead it shows that error message

2
  • 4
    the last line of the error tells you what's wrong :) btw: better format the error as code to make it easily readable Commented Dec 21, 2022 at 18:04
  • 3
    Study packages and understand the module system. Commented Dec 21, 2022 at 19:34

1 Answer 1

3

Java Platform Module System

In your error message, unnamed package not allowed in module is the key here.

Check your module-info.java file created by the JavaFX project template in IntelliJ. Be sure to edit that file to keep up with changes you make.

👉 I would guess that you changed the names of your classes and/or packages but did not edit your module-info.java file to suit.

Tip: When changing names of classes and packages in your app in IntelliJ, use IntelliJ’s Refactor features. When doing so, the module-info.java file should be automatically updated. See manual on Rename refactorings

When using JavaFX, you must learn about the Java Platform Module System. While optional for some other kinds of Java apps, compliance with Java modularity is required of JavaFX apps.

As commented, for working with JavaFX, you must understand both Java packages and Java modules. Resources include:

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.