Java:应用程序启动方法java.lang.reflect.InvocationTargetException中的异常[重复]

问题描述 投票:0回答:1

我一直在尝试执行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>

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

java intellij-idea javafx fxml
1个回答
0
投票

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

© www.soinside.com 2019 - 2024. All rights reserved.