title: JavaFX, why is TableColumn null?
body: <p>As you will see I am a massive noob when it comes to Java and Javafx. I have spent a lot of time reading around (various forum posts, and tuts) and trying to figure out myself where I am getting this issue but it has come to the point for me to post for feedback from someone who knows their business.</p>
  
  <p>When replying, please could you take the time to also explain why something isn't working and some general pointers? Here is what I have so far (my FXML and my two classes) any pointers would be fantastic!!</p>
  
  <p>My FXML;</p>
  
  <pre><code>&lt;Pane id="myScene" fx:id="myScene" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity"
        prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1"
          fx:controller="sample.TestController"&gt;
     &lt;children&gt;
        &lt;TableView id="employeesTable" fx:id="employeesTable" layoutX="131.0" layoutY="64.0" prefHeight="200.0" prefWidth="360.0"&gt;
          &lt;columns&gt;
            &lt;TableColumn id="colFirstName" fx:id="colFirstName" prefWidth="75.0" text="First Name" /&gt;
            &lt;TableColumn id="colLastName" fx:id="colLastName" prefWidth="75.0" text="Last Name" /&gt;
              &lt;TableColumn id="colEmail" fx:id="colEmail" prefWidth="75.0" text="email" /&gt;
          &lt;/columns&gt;
        &lt;/TableView&gt;
     &lt;/children&gt;
  &lt;/Pane&gt;
  </code></pre>
  
  <p>Now the Employee class I have;</p>
  
  <pre><code>public class Employee {
  
  private StringProperty firstName;
  private StringProperty lastName;
  private StringProperty email;
  
  
  public Employee(String a, String b, String c) {
      this.firstName = new SimpleStringProperty(a);
      this.lastName = new SimpleStringProperty(b);
      this.email = new SimpleStringProperty(c);
  }
  
  public Employee() {
  }
  
  
  public String getFirstName() {
      return firstName.get();
  }
  
  public StringProperty firstNameProperty() {
      return firstName;
  }
  
  public void setFirstName(String firstName) {
      this.firstName.set(firstName);
  }
  
  public String getLastName() {
      return lastName.get();
  }
  
  public StringProperty lastNameProperty() {
      return lastName;
  }
  
  public void setLastName(String lastName) {
      this.lastName.set(lastName);
  }
  
  public String getEmail() {
      return email.get();
  }
  
  public StringProperty emailProperty() {
      return email;
  }
  
  public void setEmail(String email) {
      this.email.set(email);
  }
  </code></pre>
  
  <p>}</p>
  
  <p>And finally the class for my test controller is</p>
  
  <pre><code>public class TestController {
  public Label login;
  public TextField loginUserName;
  public PasswordField loginPassword;
  public TextField testOutput;
  @FXML TableView&lt;Employee&gt; employeesTable;
  @FXML TableColumn&lt;Employee, String&gt; colFirstName;
  @FXML TableColumn&lt;Employee, String&gt; colLastName;
  @FXML TableColumn&lt;Employee, String&gt; colEmail;
  @FXML Pane myScene;
  
  //public javafx.scene.control.TableView employeesTable;
  private ObservableList&lt;Employee&gt; myData;
  private MainController MainController;
  
  public void loadEmployeeForm(ActionEvent actionEvent) throws IOException, SQLException, ClassNotFoundException {
      myData = FXCollections.observableArrayList(DBCON.getEmployees());
      System.out.println(myData.size());
      Parent root = FXMLLoader.load(getClass().getResource("frmEmployees.fxml"));
      Scene myScene = new Scene( root );
      sample.MainController.setScene(myScene);
      colFirstName.setCellValueFactory(new PropertyValueFactory&lt;Employee, String&gt;("firstName"));
      colLastName.setCellValueFactory(new PropertyValueFactory&lt;Employee, String&gt;("lastName"));
      colEmail.setCellValueFactory(new PropertyValueFactory&lt;Employee, String&gt;("email"));
      employeesTable.setItems(null);
      employeesTable.setItems(myData);
      employeesTable.setVisible(true);
  }
  </code></pre>
  
  <p>I get a null pointer exception when I go to set colFirstName to the property value factory which make me think I haven't initialized something somewhere but I am utterly clueless on how to go about adding that.</p>
  
  <p>If I add in lines such as;
  TableColumn colFirstName = new TableColumn("firstName");</p>
  
  <p>for each of my columns and the tablename it works (ie it doesn't throw a load of error messages at me) that way but then I don't get any data loading into the tableview because I think that's me creating a new tableView not using the one generated from the FXML?</p>
  
  <p>I have a feeling it will be very simple, but as I said I am a massive noob and any points would be much obliged.</p>
  
  <p>Thanks
  Mark</p>
  
  <p>Update 1;</p>
  
  <p>The method for load employee form is called from a button on myMain.fxml;</p>
  
  <pre><code>    &lt;GridPane alignment="CENTER" hgap="10" prefHeight="300" prefWidth="300" vgap="10" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/8"
            fx:controller="sample.TestController" stylesheets="/sample/myFirst.css"&gt;
      &lt;children&gt;
         &lt;Button onAction="#login" text="Login" GridPane.halignment="CENTER" GridPane.rowIndex="5" GridPane.valignment="CENTER" /&gt;
          &lt;Button text="GoEmployees" onAction="#loadEmployeeForm" GridPane.halignment="CENTER" GridPane.rowIndex="3" GridPane.valignment="CENTER" /&gt;
         &lt;Label fx:id="login" GridPane.rowIndex="1" /&gt;
        &lt;Label text="UserName" GridPane.columnIndex="0" GridPane.rowIndex="1" /&gt;
        &lt;Label text="Password" GridPane.columnIndex="0" GridPane.rowIndex="2" /&gt;
        &lt;TextField fx:id="loginUserName" GridPane.rowIndex="1" GridPane.columnIndex="1" /&gt;
        &lt;PasswordField fx:id="loginPassword" GridPane.rowIndex="2" GridPane.columnIndex="1" blendMode="OVERLAY" /&gt;
          &lt;TextField fx:id="testOutput" GridPane.rowIndex="4" GridPane.columnIndex="0" GridPane.columnSpan="3" /&gt;
     &lt;/children&gt;
     &lt;columnConstraints&gt;
        &lt;ColumnConstraints prefWidth="125.0" /&gt;
     &lt;/columnConstraints&gt;
     &lt;rowConstraints&gt;
        &lt;RowConstraints prefHeight="50.0" /&gt;
     &lt;/rowConstraints&gt;
     &lt;padding&gt;
        &lt;Insets bottom="10.0" left="9.0" right="10.0" top="10.0" /&gt;
     &lt;/padding&gt;
  
  &lt;/GridPane&gt;
  </code></pre>
  
  <p>Is having my testController control two different FXMLs a problem/a no go?</p>