title: JavaFX: Exception in thread “JavaFX Application Thread” java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
body: <p>I am working on Java FX project 
  I'm created two FXML file and i want to load another pane to main pain which is Border Pane. I want to load another pane to Border Pane center area!</p>
  
  <p>Here is my entry point of my project that is a Java file</p>
  
  <pre><code>package javafxapplication8;
  
      import java.io.IOException;
      import javafx.application.Application;
      import javafx.fxml.FXML;
      import javafx.fxml.FXMLLoader;
      import javafx.scene.Parent;
      import javafx.scene.Scene;
      import javafx.scene.input.MouseEvent;
      import javafx.scene.layout.BorderPane;
      import javafx.stage.Stage;
  
      /**
       *
       * @author Anu
       */
      public class JavaFXApplication8 extends Application {
  
          @Override
          public void start(Stage stage) throws Exception {
              Parent root = FXMLLoader.load(getClass().getResource("FXMLDocument.fxml"));
              Scene scene = new Scene(root);
              stage.setScene(scene);
              stage.show();
          }
          @FXML
          void handleButtonAction(MouseEvent event) throws IOException {
          }
          /**
           * @param args the command line arguments
           */
          public static void main(String[] args) {
              launch(args);
          }
      }
  </code></pre>
  
  <p>After that this display the main FXML file which show my Border Pane</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
      &lt;?import com.jfoenix.controls.JFXButton?&gt;
      &lt;?import javafx.scene.layout.AnchorPane?&gt;
      &lt;?import javafx.scene.layout.BorderPane?&gt;
  
      &lt;AnchorPane id="AnchorPane" prefHeight="200" prefWidth="320" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/8.0.171" 
                  fx:controller="javafxapplication8.FXMLDocumentController"&gt;
         &lt;children&gt;
            &lt;BorderPane fx:id="rootStage" layoutX="14.0" layoutY="-14.0" prefHeight="200.0" prefWidth="320.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0"&gt;
               &lt;left&gt;
                  &lt;JFXButton buttonType="RAISED" 
                             onAction="#handleButtonAction"
                              text="Load Pane" BorderPane.alignment="CENTER" /&gt;
               &lt;/left&gt;
            &lt;/BorderPane&gt;
         &lt;/children&gt;
      &lt;/AnchorPane&gt;
  </code></pre>
  
  <p>I set a button to display specific pane to that Border Pane center area. </p>
  
  <pre><code>&lt;left&gt;
     &lt;JFXButton buttonType="RAISED" 
      onAction="#handleButtonAction"
      text="Load Pane" BorderPane.alignment="CENTER" /&gt;
  &lt;/left&gt;
  </code></pre>
  
  <p>This is my Controller class of that Border Pane contained class</p>
  
  <pre><code>package javafxapplication8;
  
      import java.io.IOException;
      import java.net.URL;
      import java.util.ResourceBundle;
      import javafx.event.ActionEvent;
      import javafx.fxml.FXML;
      import javafx.fxml.FXMLLoader;
      import javafx.fxml.Initializable;
      import javafx.scene.control.Label;
      import javafx.scene.layout.BorderPane;
  
      /**
       *
       * @author Anu
       */
      public class FXMLDocumentController implements Initializable {
  
          @FXML
          private BorderPane rootStage;
  
          @FXML
          private void handleButtonAction(ActionEvent event) throws IOException {
              System.out.println("Button Click");
              FXMLLoader loader = new FXMLLoader();  
              loader.setLocation(javafx.stage.Stage.class.getResource("FXML.fxml"));  
  
              BorderPane newScene = loader.load();  
              rootStage.setCenter(newScene);  
          }
  
          @Override
          public void initialize(URL url, ResourceBundle rb) {
              // TODO
              System.out.println("FXMLDocumentController");
          }    
  
      }
  </code></pre>
  
  <p>And this is FXML file i want to display in Border Pane center area.</p>
  
  <pre><code>        &lt;?xml version="1.0" encoding="UTF-8"?&gt;
      &lt;?import javafx.scene.control.Label?&gt;
      &lt;?import javafx.scene.layout.AnchorPane?&gt;
      &lt;?import javafx.scene.text.Font?&gt;
  
      &lt;AnchorPane id="AnchorPane" prefHeight="400.0" prefWidth="600.0" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/8.0.171" fx:controller="javafxapplication8.FXMLController"&gt;
         &lt;children&gt;
            &lt;Label layoutX="252.0" layoutY="179.0" text="Label"&gt;
               &lt;font&gt;
                  &lt;Font size="41.0" /&gt;
               &lt;/font&gt;
            &lt;/Label&gt;
         &lt;/children&gt;
      &lt;/AnchorPane&gt;
  </code></pre>
  
  <p>But when i click Button That give me bunch of errors!</p>
  
  <pre><code>Executing C:\Users\Anu\Documents\NetBeansProjects\JavaFXApplication8\dist\run922593932\JavaFXApplication8.jar using platform C:\Program Files\Java\jdk1.8.0_172\jre/bin/java
      FXMLDocumentController
      Button Click
      Exception in thread "JavaFX Application Thread" java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
          at javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1774)
          at javafx.fxml.FXMLLoader$ControllerMethodEventHandler.handle(FXMLLoader.java:1657)
          at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)
          at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
          at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
          at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
          at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
          at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
          at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
          at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
          at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
          at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
          at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
          at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:49)
          at javafx.event.Event.fireEvent(Event.java:198)
          at javafx.scene.Node.fireEvent(Node.java:8411)
          at javafx.scene.control.Button.fire(Button.java:185)
          at com.sun.javafx.scene.control.behavior.ButtonBehavior.mouseReleased(ButtonBehavior.java:182)
          at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:96)
          at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:89)
          at com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(CompositeEventHandler.java:218)
          at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:80)
          at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
          at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
          at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
          at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
          at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
          at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
          at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
          at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
          at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
          at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
          at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
          at javafx.event.Event.fireEvent(Event.java:198)
          at javafx.scene.Scene$MouseHandler.process(Scene.java:3757)
          at javafx.scene.Scene$MouseHandler.access$1500(Scene.java:3485)
          at javafx.scene.Scene.impl_processMouseEvent(Scene.java:1762)
          at javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2494)
          at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:394)
          at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:295)
          at java.security.AccessController.doPrivileged(Native Method)
          at com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$353(GlassViewEventHandler.java:432)
          at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:389)
          at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:431)
          at com.sun.glass.ui.View.handleMouseEvent(View.java:555)
          at com.sun.glass.ui.View.notifyMouse(View.java:937)
          at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
          at com.sun.glass.ui.win.WinApplication.lambda$null$147(WinApplication.java:177)
          at java.lang.Thread.run(Thread.java:748)
      Caused by: 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 sun.reflect.misc.Trampoline.invoke(MethodUtil.java:71)
          at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
          at java.lang.reflect.Method.invoke(Method.java:498)
          at sun.reflect.misc.MethodUtil.invoke(MethodUtil.java:275)
          at javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1769)
          ... 48 more
      Caused by: java.lang.IllegalStateException: Location is not set.
          at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2434)
          at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2409)
          at javafxapplication8.FXMLDocumentController.handleButtonAction(FXMLDocumentController.java:33)
          ... 58 more
  </code></pre>
  
  <p>My project structure:</p>
  
  <p><a href="https://i.stack.imgur.com/Qx6hI.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Qx6hI.png" alt="Project structure screenshot"></a></p>
  
  <p>Can anybody show me where i am missed? Thank you.</p>