0

I have a project with 2 windows, the first one pass parameter to the second, but when running the project, the main class doesn't lunch the window, instead I've got this exception:

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)

here is my main code:

@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();
}

I've read all the posts about InvocationTargetException but it seems not the same problem, I can't understand where is the error, I've the same code on another project and it works (sorry I'm neww with javaFx, it's just my second project).

here is the FXML file:

<?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>

Thanks

devhicham
  • 557
  • 2
  • 6
  • 14

1 Answers1

0

Comment out //

//primaryStage.getIcons().add(new Image("img/icon.png"));
SedJ601
  • 12,173
  • 3
  • 41
  • 59