title: How to get a reference to the nodes described via fx:id in javafx?
body: <p>I have a reduced example of my problem where the code references from <code>fx:id</code> are not null when the <code>initialize</code> is called but then go to null right after the function call. What is the correct way to get such references? This is <code>sample.fxml</code></p>
  
  <pre><code>&lt;GridPane alignment="center" hgap="10" vgap="10" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/8" fx:controller="sample.Main"&gt;
     &lt;columnConstraints&gt;
        &lt;ColumnConstraints /&gt;
     &lt;/columnConstraints&gt;
     &lt;rowConstraints&gt;
        &lt;RowConstraints /&gt;
     &lt;/rowConstraints&gt;
     &lt;children&gt;
        &lt;Text fx:id="textRef" strokeType="OUTSIDE" strokeWidth="0.0" text="Hello world" /&gt;
     &lt;/children&gt;
  &lt;/GridPane&gt;
  </code></pre>
  
  <p>And this is the <code>Main.java</code> which is declared as its controller.</p>
  
  <pre><code>public class Main extends Application implements Initializable{
      @FXML
      public Text textRef;
  
      @Override
      public void start(Stage primaryStage) throws Exception{
          Parent root = FXMLLoader.load(getClass().getResource("sample.fxml"));
          primaryStage.setTitle("Hello World");
          primaryStage.setScene(new Scene(root, 300, 275));
          primaryStage.show();
  
          this.someNewFunction();
      }
  
      private void someNewFunction() {
          this.textRef.setText("Changed in somNewFunction");
      }
  
  
      public static void main(String[] args) {
          launch(args);
      }
  
      @Override
      public void initialize(URL location, ResourceBundle resources) {
          this.textRef.setText("Changed at initialize");
      }
  }
  </code></pre>
  
  <p>The text ref is valid inside the <code>initialize</code> call but throws a nullpointerexception when inside the <code>someNewFunction</code>.</p>