InvocationTargetException when running javafx 11 program

Viewed 10110

I got my code to run when I copied and pasted my code into another javafx program that I had created a few weeks ago, but for some reason, whenever I create new javafx programs, I cannot get them to run and get these errors:

Exception in Application start method
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 javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:464)
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:363)
    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: Exception in Application start method
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:900)
    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.IllegalAccessError: superclass access check failed: class com.sun.javafx.scene.control.ControlHelper (in unnamed module @0xb69df6e) cannot access class com.sun.javafx.scene.layout.RegionHelper (in module javafx.graphics) because module javafx.graphics does not export com.sun.javafx.scene.layout to unnamed module @0xb69df6e
    at java.base/java.lang.ClassLoader.defineClass1(Native Method)
    at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1016)
    at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:174)
    at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:802)
    at java.base/jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(BuiltinClassLoader.java:700)
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:623)
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
    at javafx.scene.control.Control.<clinit>(Control.java:86)
    at Homework4.Homework4.start(Homework4.java:24)
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:846)
    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.win.WinApplication._runLoop(Native Method)
    at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:174)
    ... 1 more
Exception running application Homework4.Homework4

I think that something is wrong with my JDK11 / JavaFX11 that does not allow me to create any more JavaFX projects because something is making each new project have this compile error. I think the error is due to the java.lang.IllegalAccessError but I have no idea how to fix it.

Here is my code for reference:

package Homework4;

import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.TextField;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;


public class Homework4 extends Application {

    private TextField firstNum;
    private TextField secondNum;
    private Button plus;
    private Button equals;
    private TextField result;

    @Override
    public void start(Stage stage) {
        firstNum = new TextField();
        firstNum.setMaxWidth(100);
        firstNum.setOnAction(event -> handleEquals(event));

        secondNum = new TextField();
        secondNum.setMaxWidth(100);
        secondNum.setOnAction(event -> handleEquals(event));

        plus = new Button("+");
        plus.setOnAction(event -> handleEquals(event));

        equals = new Button("=");
        equals.setOnAction(event -> handleEquals(event));

        result = new TextField();
        result.setEditable(false);

        HBox innerPane = new HBox();
        innerPane.setSpacing(10);
        innerPane.setPadding(new Insets(10, 10, 10, 10));
        innerPane.getChildren().addAll(firstNum, plus, secondNum, equals);

        VBox pane = new VBox();
        pane.setPadding(new Insets(10, 10, 10, 10));
        pane.getChildren().addAll(innerPane, result);

        stage.setScene(new Scene(pane));
        stage.setTitle("Welcome to Calculator 3000!");
        stage.show();

    }

    private void handleEquals(ActionEvent event){
        if(!(firstNum.getText().equals("") || secondNum.getText().equals(""))){
            result.setText(firstNum.getText() + secondNum.getText());
        }
    }

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

}

I am currently using the most recently updated IntelliJ Idea to code.

Side note, I am currently a Freshman in college just starting to create javafx projects, so any help/suggestions are welcome!

I tried to look at this thread for help: InvocationTargetException when running a javafx program

Unfortunately I do not have the coding knowledge to understand the suggestions that people posted in this thread.

1 Answers

It turns out that I did not set up IntelliJ correctly, which resulted in my InvocationTargetException. Assuming that all of your environmental variables are correct, follow these instructions to possibly fix the exception.

Related