2017-03-03 3 views
0

J'ai un projet avec 2 fenêtres, le premier paramètre d'une passe à la seconde, mais lors de l'exécution du projet, la classe principale ne déjeune pas la fenêtre, à la place j'ai cette exception:JavaFx InvocationTargetException Exception Chargement d'une fenêtre

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) 

voici mon code principal:

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

J'ai lu tous les messages sur InvocationTargetException mais il ne semble pas le même problème, je ne peux pas comprendre où est l'erreur, je l'ai le même code sur un autre projet et ça marche (désolé je suis nouveau avec javaFx, c'est juste mon projet de cond).

ici est le fichier 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> 

Merci

+0

Où est le fichier 'Choices.fxml' situé? – DVarga

+0

le tout dans le même paquet – devhicham

+0

Si vous Choices.fxml est correct commentez la partie d'icône. – Sedrick

Répondre

0

Commentez //

//primaryStage.getIcons().add(new Image("img/icon.png"));