title: java.lang.NullPointerException in handling with FXML inside another FXML in Javafx
body: <p>I have been trying to figure out how to deal with a FXML file in another FXML file. But I have an exception. :(
  This is my inner FXML (NewInside.fxml in view package):</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  
  &lt;?import javafx.scene.control.*?&gt;
  &lt;?import java.lang.*?&gt;
  &lt;?import javafx.scene.layout.*?&gt;
  &lt;?import javafx.scene.layout.AnchorPane?&gt;
  
  
  &lt;AnchorPane prefHeight="305.0" prefWidth="360.0" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/8" fx:controller="controller.NewInsideController"&gt;
     &lt;children&gt;
        &lt;Button fx:id="newBtn" layoutX="30.0" layoutY="202.0" mnemonicParsing="false" onAction="#btnClick" text="Button" /&gt;
        &lt;TextField fx:id="newTxt" layoutX="30.0" layoutY="134.0" prefHeight="25.0" prefWidth="280.0" /&gt;
        &lt;Label fx:id="newLbl" layoutX="30.0" layoutY="62.0" prefHeight="17.0" prefWidth="280.0" /&gt;
     &lt;/children&gt;
  &lt;/AnchorPane&gt;
  </code></pre>
  
  <p>This is its controller (NewInsideController.java in controller package):</p>
  
  <pre><code>package controller;
  
  import java.net.URL;
  import java.util.ResourceBundle;
  
  import javafx.event.ActionEvent;
  import javafx.fxml.FXML;
  import javafx.fxml.Initializable;
  import javafx.scene.control.Button;
  import javafx.scene.control.Label;
  import javafx.scene.control.TextField;
  
  public class NewInsideController implements Initializable{
  
      @FXML public static Label newLbl;
      @FXML public static TextField newTxt;
      @FXML public static Button newBtn;
  
      @Override
      public void initialize(URL location, ResourceBundle resources) {
  
      }
  
      @FXML
      private void btnClick(ActionEvent e){
          System.out.println("Button is clicked!");
          newLbl.setText(newTxt.getText());
      }
  
  }
  </code></pre>
  
  <p>And this is outer FXML (New.fxml in view package):</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  
  &lt;?import javafx.scene.control.*?&gt;
  &lt;?import java.lang.*?&gt;
  &lt;?import javafx.scene.layout.*?&gt;
  &lt;?import javafx.scene.layout.AnchorPane?&gt;
  
  
  &lt;AnchorPane prefHeight="380.0" prefWidth="529.0" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/8" fx:controller="controller.NewController"&gt;
     &lt;children&gt;
        &lt;fx:include source="NewInside.fxml" /&gt;
     &lt;/children&gt;
  &lt;/AnchorPane&gt;
  </code></pre>
  
  <p>This is its controller (NewController.java in controller package):</p>
  
  <pre><code>package controller;
  
  import java.net.URL;
  import java.util.ResourceBundle;
  import javafx.fxml.Initializable;
  
  public class NewController implements Initializable {
  
      /*@FXML private Label newLbl;
      @FXML private Button newBtn;
      @FXML private TextField newTxt;
      */
  
      @Override
      public void initialize(URL location, ResourceBundle resources) {
  
      }
  
      /*@FXML
      public void btnClick(ActionEvent e){
          newLbl.setText(newTxt.getText());
      }*/
  
  }
  </code></pre>
  
  <p>Finally, this is the Main.java in application package:</p>
  
  <pre><code>package application;
  
  import javafx.application.Application;
  import javafx.fxml.FXMLLoader;
  import javafx.stage.Stage;
  import javafx.scene.Parent;
  import javafx.scene.Scene;
  
  
  public class Main extends Application {
      @Override
      public void start(Stage primaryStage) {
          try {
              Parent root = FXMLLoader.load(getClass().getResource("/view/New.fxml"));
              Scene scene = new Scene(root);
              scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
              primaryStage.setScene(scene);
              primaryStage.show();
          } catch(Exception e) {
              e.printStackTrace();
          }
      }
  
      public static void main(String[] args) {
          launch(args);
      }
  }
  </code></pre>
  
  <p>When I clicked the button, it gives me very long exception:
  "Exception in thread "JavaFX Application Thread" java.lang.RuntimeException: java.lang.reflect.InvocationTargetException....
  .....
  Caused by: java.lang.NullPointerException
      at controller.NewInsideController.btnClick(NewInsideController.java:27)
      ... 57 more"</p>
  
  <p>Please help me! :(</p>