title: Java FX 8, trouble setting the value of text field
body: <p>I'm trying to populate the value of a text field in Java FX.</p>
  
  <p>I have the Main Class,the controller and the fxml.I have bind the fxml file with controller and the appropriate field in it. When i try to set its value, it fails.</p>
  
  <p>Main.java</p>
  
  <pre><code>import javafx.application.Application;
  import javafx.fxml.FXMLLoader;
  import javafx.scene.Scene;
  import javafx.scene.layout.FlowPane;
  import javafx.stage.Stage;
  
  
  public class Main extends Application {
  
      private Stage primaryStage;
      private FlowPane rootLayout;
  
      @Override
      public void start(Stage primaryStage) {
          try {
  
  
              FXMLLoader loader = new FXMLLoader();
              loader.setLocation(Main.class.getResource("test.fxml"));            
              rootLayout = (FlowPane) loader.load();                      
              Scene scene = new Scene(rootLayout);
              primaryStage.setScene(scene);
              primaryStage.show();
  
  
  
          } catch(Exception e) {
              e.printStackTrace();
          }
      }
  
      public static void main(String[] args) {
          launch(args);
      }
  }
  </code></pre>
  
  <p>testController.java</p>
  
  <pre><code>package application;
  
  import javafx.fxml.FXML;
  import javafx.scene.control.TextField;
  
  public class testController {
  
      @FXML
      private TextField t1;
  
      public testController() {
  
          System.out.println("hi");
          t1 = new TextField("j");
          t1.setText("hi");
  
      }
  
  
  
  }
  </code></pre>
  
  <p>FXML file:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  
  &lt;?import java.lang.*?&gt;
  &lt;?import javafx.scene.control.*?&gt;
  &lt;?import javafx.scene.layout.*?&gt;
  &lt;?import javafx.scene.layout.FlowPane?&gt;
  
  &lt;FlowPane prefHeight="200.0" prefWidth="200.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.testController"&gt;
     &lt;children&gt;
        &lt;TextField fx:id="t1" /&gt;
     &lt;/children&gt;
  &lt;/FlowPane&gt;
  </code></pre>