JavaFX问题:应用程序启动方法java.lang.reflect.InvocationTargetException中的异常

时间:2020-10-16 18:48:58

标签: java intellij-idea javafx

每次尝试在IntelliJ中运行JavaFX程序时,都会遇到此问题,但我不知道如何解决它。 这是我得到的错误:

Exception in Application start method
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:64)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:564)
    at java.base/sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:1071)
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:832)
Caused by: java.lang.IllegalAccessError: superclass access check failed: class com.sun.javafx.scene.control.ControlHelper (in unnamed module @0x166469aa) 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 @0x166469aa
    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:151)
    at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:825)
    at java.base/jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(BuiltinClassLoader.java:723)
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:646)
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:604)
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:168)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
    at javafx.scene.control.Control.<clinit>(Control.java:86)
    at equationpkg.EquationsGUI.start(EquationsGUI.java:39)
    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(AccessController.java:391)
    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

还有我的代码EquationsGUI.java:

package equationpkg;

import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.geometry.Point2D;
import javafx.scene.Scene;
import javafx.scene.chart.*;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;


public class EquationsGUI extends Application {

    private Label m1Label;
    private TextField m1TextBox;
    private Label b1Label;
    private TextField b1TextBox;
    private Label m2Label;
    private TextField m2TextBox;
    private Label b2Label;
    private TextField b2TextBox;
    private Label resultLabel;
    private TextField resultTextBox;
    private LineChart chart;

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

        m1Label = new Label("m1");
        m1TextBox = new TextField();
        b1Label = new Label("b1");
        b1TextBox = new TextField();
        m2Label = new Label("m2");
        m2TextBox = new TextField();
        b2Label = new Label("b2");
        b2TextBox = new TextField();
        Button b = new Button("Solve");
        resultLabel = new Label("Result");
        resultTextBox = new TextField();

        // The grid is our container.
        // We will add all our GUI components to it.
        // GridPanes have rows and columns, but note that the
        // column comes before  the row in the parameter lists
        GridPane grid = new GridPane();
        grid.setHgap(10);   // sets the horizontal spacing
        grid.setVgap(10);   // sets the vertical spacing

        // Sets the padding around the edges of the container
        grid.setPadding(new Insets(10, 10, 10, 10));

        // Add the first label and TextBox to the GUI
        grid.add(m1Label, 0, 0);
        grid.add(m1TextBox, 1, 0);

        // Add the first label and TextBox to the GUI
        grid.add(b1Label, 0, 1);
        grid.add(b1TextBox, 1, 1);

        // Code for Checkpoint 2 goes here
        grid.add(m2Label, 0, 2);
        grid.add(m2TextBox, 1, 2);

        grid.add(b2Label, 0, 3);
        grid.add(b2TextBox, 1, 3);

        grid.add(b, 0, 4);

        grid.add(resultLabel, 0, 5 );
        grid.add(resultTextBox, 1, 5);
        // Code for CheckPoint 3 goes here
        b.setOnAction(new Solver());
        // Code for Checkpoint 4 goes here
        chart = new LineChart(new CategoryAxis(), new CategoryAxis());
        grid.add(chart, 2, 0, 3, 6);
        chart.setTitle("Graph of Line");
        chart.getXAxis().setAutoRanging(true);
        chart.getYAxis().setAutoRanging(true);

        double m1 = Double.parseDouble(m1TextBox.getText());
        double m2 = Double.parseDouble(m2TextBox.getText());
        double b1 = Double.parseDouble(b1TextBox.getText());
        double b2 = Double.parseDouble(b2TextBox.getText());
        LinearEquation eq1 = new LinearEquation(m1, b1);
        LinearEquation eq2 = new LinearEquation(m2, b2);

        XYChart.Series series1 = new XYChart.Series();
        series1.getData().add(new XYChart.Data<>("0", eq1.eval(0)));
        series1.getData().add(new XYChart.Data<>("5", eq1.eval(5)));
        chart.getData().add(series1);



        primaryStage.setTitle("Equation Solver");
        primaryStage.setScene(new Scene(grid));
        primaryStage.show();
    }

    // Code for CheckPoint solver() 3 goes here (and below)
    public class Solver extends EquationsGUI implements EventHandler<ActionEvent> {
        @Override
        public void handle(ActionEvent e) {
            double m1 = Double.parseDouble(m1TextBox.getText());
            double m2 = Double.parseDouble(m2TextBox.getText());
            double b1 = Double.parseDouble(b1TextBox.getText());
            double b2 = Double.parseDouble(b2TextBox.getText());

            LinearEquation eq1 = new LinearEquation(m1, b1);
            LinearEquation eq2 = new LinearEquation(m2, b2);

            SimultaneousEquations se = new SimultaneousEquations(eq1, eq2);
            resultTextBox.setText(se.solve().toString());
        }
    }

}

我相信我的模块路径运行正常,但是我可能错了。 我不太确定出了什么问题,对知道这一点的人将不胜感激。

0 个答案:

没有答案