我有一个带有2个窗口的项目,第一个将参数传递给第二个,但是在运行项目时,主类不会在窗口中休息,而是我有这个例外:
Exception in Application start method java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:389)
at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:767) Caused by: java.lang.RuntimeException: Exception in Application start method
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:917)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$155(LauncherImpl.java:182)
at java.lang.Thread.run(Thread.java:745) Caused by: java.lang.NullPointerException: Location is required.
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3207)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3175)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3148)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3124)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3104)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:3097)
at tic_tac_toe.TIC_TAC_TOE.start(TIC_TAC_TOE.java:21)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$162(LauncherImpl.java:863)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$175(PlatformImpl.java:326)
at com.sun.javafx.application.PlatformImpl.lambda$null$173(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(PlatformImpl.java:294)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$148(WinApplication.java:191)
这是我的主要代码:
@Override
public void start(Stage primaryStage) throws IOException {
Parent root = FXMLLoader.load(getClass().getResource("Choices.fxml"));
Scene scene = new Scene(root);
primaryStage.setScene(scene);
primaryStage.setTitle("Tic Tac Toe");
primaryStage.getIcons().add(new Image("img/icon.png"));
primaryStage.setResizable(false);
primaryStage.show();
}
我已经阅读了有关InvocationTargetException的所有帖子,但它似乎不是同一个问题,我无法理解错误在哪里,我在另一个项目上有相同的代码并且它有效(对不起我是新手javaFx ,这只是我的第二个项目。)
这是FXML文件:
<?xml version="1.0" encoding="UTF-8"?>
<?import com.jfoenix.controls.JFXButton?>
<?import com.jfoenix.controls.JFXRadioButton?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.image.Image?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.layout.Pane?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.text.Font?>
<AnchorPane id="AnchorPane" prefHeight="266.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1" fx:controller="tic_tac_toe.ChoicesController">
<children>
<BorderPane prefHeight="258.0" prefWidth="600.0" AnchorPane.bottomAnchor="51.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<top>
<Pane prefHeight="100.0" prefWidth="600.0" BorderPane.alignment="CENTER">
<children>
<Label layoutX="170.0" layoutY="23.0" prefHeight="50.0" prefWidth="344.0" text="Veuiller choisr un mode de jeux :">
<font>
<Font size="18.0" />
</font>
</Label>
<ImageView fitHeight="78.0" fitWidth="81.0" layoutX="70.0" layoutY="10.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@../img/question-speech-bubble.png" />
</image>
</ImageView>
</children>
</Pane>
</top>
<center>
<Pane prefHeight="97.0" prefWidth="600.0" BorderPane.alignment="CENTER">
<children>
<VBox layoutX="29.0" layoutY="8.0" prefHeight="80.0" prefWidth="549.0">
<children>
<JFXRadioButton fx:id="rdJoueur" prefHeight="50.0" text="Un joueur avec une machine">
<font>
<Font size="18.0" />
</font>
</JFXRadioButton>
<JFXRadioButton fx:id="rdMachine" prefHeight="50.0" text="Deux machines">
<font>
<Font size="18.0" />
</font>
</JFXRadioButton>
</children>
</VBox>
</children>
</Pane>
</center>
</BorderPane>
<Pane layoutX="-3.0" layoutY="198.0" prefHeight="58.0" prefWidth="600.0">
<children>
<JFXButton fx:id="btnOk" buttonType="RAISED" layoutX="479.0" layoutY="15.0" prefHeight="35.0" prefWidth="100.0" ripplerFill="#ffffff00" style="-fx-background-color: #2196f3;" text="Valider" textFill="WHITE">
<font>
<Font size="14.0" />
</font>
</JFXButton>
<JFXButton fx:id="btnCancel" buttonType="RAISED" layoutX="360.0" layoutY="15.0" prefHeight="35.0" prefWidth="100.0" ripplerFill="#ffffff00" style="-fx-background-color: #2196f3;" text="Annuler" textFill="WHITE">
<font>
<Font size="14.0" />
</font>
</JFXButton>
</children>
</Pane>
</children>
</AnchorPane>
由于
答案 0 :(得分:0)
评论//
//primaryStage.getIcons().add(new Image("img/icon.png"));