title: JavaFX TableView NullPointerException
body: <p>I have application that display database result in JavaFX TreeView. I made it exactly as mentioned in <a href="https://stackoverflow.com/a/18634486/7185289">this Answer</a>.
  But when i run the program i get an error like below. <br>The error is pointing to the <code>tblView.setItems(data)</code> method in controller. </p>
  
  <p>how may i solve this..?</p>
  
  <pre><code>java.lang.NullPointerException
      at demofx.FXMLDocumentController.buildData(FXMLDocumentController.java:105)
      at demofx.FXMLDocumentController.initialize(FXMLDocumentController.java:85)
      at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2548)
      at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2441)
      at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3214)
      at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3175)
      at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3148)
      at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3124)
      at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3104)
      at javafx.fxml.FXMLLoader.load(FXMLLoader.java:3097)
      at demofx.DemoFX.start(DemoFX.java:23)
      at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$162(LauncherImpl.java:863)
      at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$175(PlatformImpl.java:326)
      at com.sun.javafx.application.PlatformImpl.lambda$null$173(PlatformImpl.java:295)
      at java.security.AccessController.doPrivileged(Native Method)
      at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(PlatformImpl.java:294)
      at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
      at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
      at com.sun.glass.ui.win.WinApplication.lambda$null$148(WinApplication.java:191)
      at java.lang.Thread.run(Thread.java:745)
  </code></pre>
  
  <p><br>
  <br>
  <strong>This is My .fxml Document</strong></p>
  
  <pre><code>&lt;AnchorPane id="AnchorPane" prefHeight="537.0" prefWidth="736.0" xmlns="http://javafx.com/javafx/8.0.60" xmlns:fx="http://javafx.com/fxml/1" fx:controller="demofx.FXMLDocumentController"&gt;
     &lt;children&gt;
        &lt;Label fx:id="lblAuto_id" layoutX="53.0" layoutY="31.0" text="Label" textFill="#da1b1b"&gt;
           &lt;font&gt;
              &lt;Font size="19.0" /&gt;
           &lt;/font&gt;
        &lt;/Label&gt;
        &lt;Label fx:id="lblVtype" layoutX="229.0" layoutY="89.0" text="Selected type" /&gt;
        &lt;TableView fx:id="tblVehicle" layoutX="38.0" layoutY="142.0" prefHeight="200.0" prefWidth="660.0"&gt;
          &lt;columns&gt;
            &lt;TableColumn fx:id="c_reg" prefWidth="71.0" text="Reg no" /&gt;
            &lt;TableColumn fx:id="c_make" prefWidth="79.0" text="Make" /&gt;
              &lt;TableColumn fx:id="c_model" prefWidth="75.0" text="Model" /&gt;
              &lt;TableColumn fx:id="c_year" prefWidth="75.0" text="year" /&gt;
              &lt;TableColumn fx:id="c_color" prefWidth="75.0" text="color" /&gt;
              &lt;TableColumn fx:id="c_odo" prefWidth="75.0" text="odo" /&gt;
              &lt;TableColumn fx:id="c_status" prefWidth="75.0" text="status" /&gt;
              &lt;TableColumn fx:id="c_fuel" prefWidth="75.0" text="fuel" /&gt;
              &lt;TableColumn fx:id="c_type" prefWidth="75.0" text="type" /&gt;
          &lt;/columns&gt;
        &lt;/TableView&gt;
        &lt;ComboBox fx:id="cmbVehicleType" layoutX="30.0" layoutY="85.0" onAction="#handleButtonAction" prefWidth="150.0" /&gt;
     &lt;/children&gt;
  &lt;/AnchorPane&gt;
  </code></pre>
  
  <p><br>
  <br></p>
  
  <p><strong>This is Controller</strong></p>
  
  <pre><code>public class FXMLDocumentController implements Initializable {
  
      @FXML
      private Label lblAuto_id;
      @FXML
      private ComboBox cmbVehicleType;
      @FXML
      private Label lblVtype;
  
      @FXML private TableView&lt;Veh&gt; tblView;
  
      @FXML private TableColumn &lt;Veh,String&gt;  c_reg;
      @FXML private TableColumn &lt;Veh,String&gt;  c_make;
      @FXML private TableColumn &lt;Veh,String&gt;  c_model;
      @FXML private TableColumn &lt;Veh,String&gt;  c_year;
      @FXML private TableColumn &lt;Veh,String&gt;  c_color;
      @FXML private TableColumn &lt;Veh,String&gt;  c_odo;
      @FXML private TableColumn &lt;Veh,String&gt;  c_status;
      @FXML private TableColumn &lt;Veh,String&gt;  c_fuel;
      @FXML private TableColumn &lt;Veh,String&gt;  c_type;
  
      private ObservableList&lt;Veh&gt; data;
  
  
  
      DBConnection db = new DBConnection();
  
      @FXML
      private void handleButtonAction(ActionEvent event) {
  
      }
  
      @Override
      public void initialize(URL url, ResourceBundle rb) {
  
          c_reg.setCellValueFactory(new PropertyValueFactory&lt;Veh, String&gt;("regno"));
          c_make.setCellValueFactory(new PropertyValueFactory&lt;Veh, String&gt;("make"));
          c_model.setCellValueFactory(new PropertyValueFactory&lt;Veh, String&gt;("model"));
          c_year.setCellValueFactory(new PropertyValueFactory&lt;Veh, String&gt;("type"));
          c_color.setCellValueFactory(new PropertyValueFactory&lt;Veh, String&gt;("status"));
          c_odo.setCellValueFactory(new PropertyValueFactory&lt;Veh, String&gt;("color"));
  
         buildData();
      } 
  
      public void buildData() {
  
          try {
              Connection con = db.get_connection();
              data = FXCollections.observableArrayList();
              PreparedStatement stat = con.prepareStatement("SELECT * FROM Vehicle_tbl WHERE Status= 'IN' and V_type='CAR'");
              ResultSet rs = stat.executeQuery();
               while (rs.next()) {
                   Veh ve = new Veh();
                  ve.regno.set(rs.getString(1));
                  ve.make.set(rs.getString(2));
                  ve.model.set(rs.getString(3));
                  ve.color.set(rs.getString(4));
                  ve.status.set(rs.getString(5));
                  ve.type.set(rs.getString(6));
                  data.add(ve);
              }
              tblView.setItems(data);
  
          } catch (Exception ex) {
              ex.printStackTrace();
          }
  }
  
  }
  </code></pre>
  
  <p><br></p>
  
  <p><strong>This is the POJO Class</strong></p>
  
  <pre><code>public class Veh {
  
     public SimpleStringProperty regno = new SimpleStringProperty(); 
     public SimpleStringProperty make = new SimpleStringProperty();
     public SimpleStringProperty model = new SimpleStringProperty();
     public SimpleStringProperty type = new SimpleStringProperty();
     public SimpleStringProperty status = new SimpleStringProperty();
     public SimpleStringProperty color = new SimpleStringProperty();
  
     public String getRegno(){
         return regno.get();
     }
  
     public String getMake(){
         return make.get();
     }
  
     public String getModel(){
         return model.get();
     }
  
     public String getType(){
         return type.get();
     }
  
     public String getStatus(){
         return status.get();
     }
  
     public String getColor(){
         return color.get();
     }
  
  }
  </code></pre>