gpt4 book ai didi

Java:应用程序启动方法中出现异常 java.lang.reflect.InitationTargetException

转载 作者:行者123 更新时间:2023-12-01 18:08:22 25 4
gpt4 key购买 nike

我一直在尝试从事 Simon Says 项目,但运行该项目时不断出现错误。我正在使用 IntelliJ、Java 13.0.2 和最新版本的 JavaFX。

错误是:

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:567)
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:567)
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:830)
Caused by: java.lang.IllegalAccessError: class com.sun.javafx.fxml.FXMLLoaderHelper (in unnamed module @0x229b412d) cannot access class com.sun.javafx.util.Utils (in module javafx.graphics) because module javafx.graphics does not export com.sun.javafx.util to unnamed module @0x229b412d
at com.sun.javafx.fxml.FXMLLoaderHelper.<clinit>(FXMLLoaderHelper.java:38)
at javafx.fxml.FXMLLoader.<clinit>(FXMLLoader.java:2056)
at Main.start(Main.java:15)
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
Exception running application Main

我的主要内容是:

import javafx.application.Application;
import javafx.fxml.*;
import javafx.scene.*;
import javafx.scene.layout.AnchorPane;
import javafx.stage.Stage;

public class Main extends Application {
private Stage primaryStage;
private AnchorPane rootLayout;

public void start(Stage primaryStage) {
try {
this.primaryStage = primaryStage;
primaryStage.setTitle("Simon Game - java ripoff edition");
FXMLLoader loader = new FXMLLoader(Main.class.getResource("GUI.fxml"));
Parent root = loader.load();
Scene scene = new Scene(this.rootLayout);
primaryStage.setScene(scene);
primaryStage.show();
scene.getStylesheets().add(this.getClass().getResource("application.css").toExternalForm());
} catch (Exception var4) {
var4.printStackTrace();
}

}

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

我的 FXML 代码是:

<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.control.Button?>
<?import javafx.scene.control.TabPane?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.shape.Rectangle?>
<?import javafx.scene.text.Font?>

<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" fx:1d="root" prefHeight="400.0" prefWidth="600.0" style="-fx-background-color: silver;" xmlns="http://javafx.com/javafx/8.0.60" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.Controller">
<children>
<Button fx:id="startBtn" layoutX="466.0" layoutY="140.0" mnemonicParsing="false" onAction="#handleButtonAction" prefHeight="47.0" prefWidth="99.0" text="Start">
<font>
<Font name="Gill Sans MT" size="19.0" />
</font>
</Button>
<Rectangle fx:id="greenBtn" arcHeight="5.0" arcWidth="5.0" fill="#0ab916" height="150.0" layoutX="121.0" layoutY="51.0" onMouseClicked="#userInput" stroke="BLACK" strokeType="INSIDE" width="150.0" />
<Rectangle fx:id="redBtn" arcHeight="5.0" arcWidth="5.0" fill="#ff1f1f" height="150.0" layoutX="271.0" layoutY="51.0" onMouseClicked="#userInput" stroke="BLACK" strokeType="INSIDE" width="150.0" />
<Rectangle fx:id="yellowbtn" arcHeight="5.0" arcWidth="5.0" fill="#e8eb23" height="150.0" layoutX="121.0" layoutY="201.0" onMouseClicked="#userInput" stroke="BLACK" strokeType="INSIDE" width="150.0" />
<Rectangle fx:id="blueBtn" arcHeight="5.0" arcWidth="5.0" fill="DODGERBLUE" height="150.0" layoutX="271.0" layoutY="201.0" onMouseClicked="#userInput" stroke="BLACK" strokeType="INSIDE" width="150.0" />
<TabPane layoutX="37.0" prefHeight="200.0" prefWidth="200.0" tabClosingPolicy="UNAVAILABLE" />
<Button fx:id="instructBtn" layoutX="466.0" layoutY="208.0" mnemonicParsing="false" onAction="#handleButtonAction" prefHeight="47.0" prefWidth="99.0" text="Instructions">
<font>
<Font name="Gill Sans MT" size="16.0" />
</font>
</Button>
</children>
</AnchorPane>

我还有其他可以使用按钮的类,但我只从主类中收到错误。我们将不胜感激所有帮助!

最佳答案

您需要导入所有必需的包。

关于Java:应用程序启动方法中出现异常 java.lang.reflect.InitationTargetException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60514724/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com