title: Using scene builder and multiple controllers
body: <p>With my application growing, I'd like to create additional classes to handle the sql queries, the data validation, etc. Currently, the controller manages it all.</p>
  
  <p>However, I have no idea how to go about creating different classes that can "talk" to the components in my controller class and with my .fxml file.</p>
  
  <p>I attemped this: <a href="https://stackoverflow.com/questions/15964832/javafx-1-fxml-file-with-multiple-different-controllers">JavaFX 1 FXML File with Multiple Different Controllers?</a></p>
  
  <p>..and tried creating a new class to populate a table as follows:</p>
  
  <pre><code>import java.sql.Connection;
  import javafx.collections.ObservableList;
  import javafx.fxml.FXML;
  import javafx.fxml.FXMLLoader;
  import javafx.scene.control.TableColumn;
  import javafx.scene.control.TableView;
  import javafx.scene.control.cell.PropertyValueFactory;
  
  public class DepartmentTable {
  
      private Connection conn;
      private FXMLLoader fxmlLoader;
      @FXML
      private TableView&lt;Department&gt; departmentTableView;// = new TableView&lt;&gt;(staffTypeList);
      @FXML
      private TableColumn&lt;Department, Integer&gt; departmentIdCol;
      @FXML
      private TableColumn&lt;Department, String&gt; departmentNameCol;
      private ObservableList&lt;Department&gt; departmentList;
  
      public DepartmentTable(Connection aconn, FXMLLoader loader) {
          this.conn = aconn;
          this.fxmlLoader=loader;
          loadController();
          populateDepartmentTable();
      }
  
      private void loadController(){
          fxmlLoader.setController(this);
      }
  
      private void populateDepartmentTable() {
  
          departmentList = new DepartmentData(conn).getDepartmentList();
  
          /*Populate the Table with StaffType objects*/
          departmentIdCol.setCellValueFactory(
                  new PropertyValueFactory&lt;Department, Integer&gt;("departmentID"));
          departmentNameCol.setCellValueFactory(
                  new PropertyValueFactory&lt;Department, String&gt;("departmentName"));
  
          departmentTableView.setItems(departmentList);
      }
  }
  </code></pre>
  
  <p>However, I get an invocationTargetException which is caused by a NullPointerException at</p>
  
  <pre><code>/*Populate the Table with StaffType objects*/
          departmentIdCol.setCellValueFactory(
  </code></pre>
  
  <p>So I am not sure what to do at this point.</p>
  
  <p>Please help. Thank you!</p>