0

I am trying to configure JavaFX and as soon as I try to compile the file, it throws an InvocationTargetException with the following stack trace:

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 gameoflife.TestApplication
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:890)
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:195)
    at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: java.lang.IllegalAccessException: class com.sun.javafx.application.LauncherImpl (in module javafx.graphics) cannot access class gameoflife.TestApplication (in module gol) because module gol does not export gameoflife 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:802)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:455)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428)
    at java.base/java.security.AccessController.doPrivileged(Native Method)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:427)
    at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
    at javafx.graphics/com.sun.glass.ui.gtk.GtkApplication._runLoop(Native Method)
    at javafx.graphics/com.sun.glass.ui.gtk.GtkApplication.lambda$runLoop$11(GtkApplication.java:277)
    ... 1 more

I am using Manjaro with OpenJDK 11 (EDIT: The same thing happens when I try to compile the code on a fresh Ubuntu MATE VM). I have read a few questions on here that are similar in regards to the topic and problem. However, I do not (knowingly) use an FXML document to structure the program.

I am pretty stumped and I would greatly appreciate a bit of help in regards to resolving this issue.

Here is the code:

package gameoflife;

import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.stage.Stage;

public class TestApplication extends Application {



    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(Stage stage) throws Exception {
        Group root = new Group();
        Scene scene = new Scene(root, 300,50);
        stage.setTitle("Empty Window");
        stage.setScene(scene);
        stage.show();

    }
}
  • the stacktrace tells you what's wrong: _class com.sun.javafx.application.LauncherImpl (in module javafx.graphics) cannot access class gameoflife.TestApplication (in module gol) because module gol does not export gameoflife to module javafx.graphics_ - sounds like an incomplete module-info .. – kleopatra Jan 15 '20 at 15:40
  • @Slaw Thanks a bunch! I added the line "exports gameoflife;" to the module-info file. It works as intended now. – Adalwin Amillion Jan 15 '20 at 16:28
  • @kleopatra Slaw linked me to a similar issue. Thanks to you, too! – Adalwin Amillion Jan 15 '20 at 16:29

0 Answers0