Home > Blockchain >  Can't get JavaFX running
Can't get JavaFX running

Time:02-20

I got an important exam in the following days and need to set up JavaFX in Eclipse for that. I tried some basic code just to see if its running and I always get this error message:

Exception in Application constructor Exception in thread "main" java.lang.reflect.InvocationTargetException at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:566) at java.base/sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:1051) Caused by: java.lang.RuntimeException: Unable to construct Application instance: class pk.klausur.ui.KlausurverwaltungUI at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:891) at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:196) at java.base/java.lang.Thread.run(Thread.java:829) Caused by: java.lang.IllegalAccessException: class com.sun.javafx.application.LauncherImpl (in module javafx.graphics) cannot access class pk.klausur.ui.KlausurverwaltungUI (in module test) because module test does not export pk.klausur.ui to module javafx.graphics at java.base/jdk.internal.reflect.Reflection.newIllegalAccessException(Reflection.java:361) at java.base/java.lang.reflect.AccessibleObject.checkAccess(AccessibleObject.java:591) at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:481) at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$8(LauncherImpl.java:803) at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:484) at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:457) at java.base/java.security.AccessController.doPrivileged(Native Method) at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:456) at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)

And this is the code to this message:

package pk.klausur.ui;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ComboBox;
import javafx.scene.control.Label;
import javafx.scene.control.ListView;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.VBox;
import javafx.scene.text.Font;
import javafx.stage.Stage;

import pk.klausur.Klausurverwaltung;
import pk.klausur.Klausur;
import pk.klausur.Bewertung;
public class KlausurverwaltungUI extends Application {

    @Override
    public void start(Stage primaryStage) throws Exception {

        Klausurverwaltung verwaltung = new Klausurverwaltung();

        ComboBox <Klausur> Klausure = new ComboBox<Klausur>();

        VBox root = new VBox();

        ListView <Bewertung> bewertunge = new ListView<Bewertung>();

        GridPane gp = new GridPane();

        Button b1 = new Button("Klausuren");

        Label l1 = new Label("test");

        l1.setFont(new Font(50));

        Scene scene = new Scene(l1);
        primaryStage.setScene(scene);
        primaryStage.show();
    }
public static void main(String[] args) {
    launch(args);
}
}

Would be awesome if someone could help and save my exam!

CodePudding user response:

As you are using idea, I would recommend that you create a new javafx project using that and to verify if it works in your environment or not. Clearly I can tell you that something wrong in the setup .. Start with an example that's guaranteed to work like I mentioned (see f.i. stackoverflow.com/questions/52467561/…),

CodePudding user response:

The important line between all the exceptions is

module test does not export pk.klausur.ui to module javafx.graphics

which you would have to fix in your module-info.java file.

  • Related