title: Null Pointer Exception while setting a CellValueFactory in Java using FXML
body: <p>So I have this block of code:</p>
  
  <pre><code>public class UIManager {
      private MainMenuService serviceBoi;
      public UIManager(){
          serviceBoi = new MainMenuService();
      }
  
  @FXML
  private ResourceBundle resources;
  
  @FXML
  private URL location;
  
  @FXML
  private TableColumn&lt;?, ?&gt; reservationBookingStatusColumn;
  
  @FXML
  private Button reservationDeleteButton;
  
  @FXML
  private Button reservationEditButton;
  
  @FXML
  private TableColumn&lt;?, ?&gt; reservationIbanColumn;
  
  @FXML
  private Button reservationNewButton;
  
  @FXML
  private TableColumn&lt;?, ?&gt; reservationRStartDateColumn;
  
  @FXML
  private TableColumn&lt;?, ?&gt; reservationRentalEndColumn;
  
  @FXML
  private Button reservationSearchButton;
  
  @FXML
  private TableColumn&lt;?, ?&gt; reservationsCustomerNameColumn;
  
  @FXML
  private Tab reservationsTab;
  
  @FXML
  private TableColumn&lt;?, ?&gt; reservationsTotalPriceColumn;
  
  @FXML
  private TableColumn&lt;VehicleDTO, Short&gt; vehicleCapacityColumn;
  
  @FXML
  private TableColumn&lt;VehicleDTO, Integer&gt; vehicleConstructionDateColumn;
  
  @FXML
  private Button vehicleDeleteButton;
  
  @FXML
  private Button vehicleEditButton;
  
  @FXML
  private TableColumn&lt;VehicleDTO, String&gt; vehicleModelNameColumn;
  
  @FXML
  private TableColumn&lt;VehicleDTO, Boolean&gt; vehicleMotorisedColumn;
  
  @FXML
  private Button vehicleNewButton;
  
  @FXML
  private TableColumn&lt;VehicleDTO, String&gt; vehiclePlateNumberColumn;
  
  @FXML
  private TableColumn&lt;VehicleDTO, Integer&gt; vehiclePowerColumn;
  
  @FXML
  private TableColumn&lt;VehicleDTO, Double&gt; vehiclePriceColumn;
  
  @FXML
  private Button vehicleSearchButton;
  
  @FXML
  private TableView&lt;VehicleDTO&gt; vehicleTable;
  
  @FXML
  private Tab vehiclesTab;
  
  
  
  @FXML
  void initialize() {
      assert reservationBookingStatusColumn != null : "fx:id=\"reservationBookingStatusColumn\" was not injected: check your FXML file 'mainMenu.fxml'.";
      assert reservationDeleteButton != null : "fx:id=\"reservationDeleteButton\" was not injected: check your FXML file 'mainMenu.fxml'.";
      assert reservationEditButton != null : "fx:id=\"reservationEditButton\" was not injected: check your FXML file 'mainMenu.fxml'.";
      assert reservationIbanColumn != null : "fx:id=\"reservationIbanColumn\" was not injected: check your FXML file 'mainMenu.fxml'.";
      assert reservationNewButton != null : "fx:id=\"reservationNewButton\" was not injected: check your FXML file 'mainMenu.fxml'.";
      assert reservationRStartDateColumn != null : "fx:id=\"reservationRStartDateColumn\" was not injected: check your FXML file 'mainMenu.fxml'.";
      assert reservationRentalEndColumn != null : "fx:id=\"reservationRentalEndColumn\" was not injected: check your FXML file 'mainMenu.fxml'.";
      assert reservationSearchButton != null : "fx:id=\"reservationSearchButton\" was not injected: check your FXML file 'mainMenu.fxml'.";
      assert reservationsCustomerNameColumn != null : "fx:id=\"reservationsCustomerNameColumn\" was not injected: check your FXML file 'mainMenu.fxml'.";
      assert reservationsTab != null : "fx:id=\"reservationsTab\" was not injected: check your FXML file 'mainMenu.fxml'.";
      assert reservationsTotalPriceColumn != null : "fx:id=\"reservationsTotalPriceColumn\" was not injected: check your FXML file 'mainMenu.fxml'.";
      assert vehicleCapacityColumn != null : "fx:id=\"vehicleCapacityColumn\" was not injected: check your FXML file 'mainMenu.fxml'.";
      assert vehicleConstructionDateColumn != null : "fx:id=\"vehicleConstructionDateColumn\" was not injected: check your FXML file 'mainMenu.fxml'.";
      assert vehicleDeleteButton != null : "fx:id=\"vehicleDeleteButton\" was not injected: check your FXML file 'mainMenu.fxml'.";
      assert vehicleEditButton != null : "fx:id=\"vehicleEditButton\" was not injected: check your FXML file 'mainMenu.fxml'.";
      assert vehicleModelNameColumn != null : "fx:id=\"vehicleModelNameColumn\" was not injected: check your FXML file 'mainMenu.fxml'.";
      assert vehicleMotorisedColumn != null : "fx:id=\"vehicleMotorisedColumn\" was not injected: check your FXML file 'mainMenu.fxml'.";
      assert vehicleNewButton != null : "fx:id=\"vehicleNewButton\" was not injected: check your FXML file 'mainMenu.fxml'.";
      assert vehiclePlateNumberColumn != null : "fx:id=\"vehiclePlateNumberColumn\" was not injected: check your FXML file 'mainMenu.fxml'.";
      assert vehiclePowerColumn != null : "fx:id=\"vehiclePowerColumn\" was not injected: check your FXML file 'mainMenu.fxml'.";
      assert vehiclePriceColumn != null : "fx:id=\"vehiclePriceColumn\" was not injected: check your FXML file 'mainMenu.fxml'.";
      assert vehicleSearchButton != null : "fx:id=\"vehicleSearchButton\" was not injected: check your FXML file 'mainMenu.fxml'.";
      assert vehicleTable != null : "fx:id=\"vehicleTable\" was not injected: check your FXML file 'mainMenu.fxml'.";
      assert vehiclesTab != null : "fx:id=\"vehiclesTab\" was not injected: check your FXML file 'mainMenu.fxml'.";
  
  
  }
  
      @FXML
  public void openNewCarWindow(){
      try{
          FXMLLoader fxload = new FXMLLoader(getClass().getResource("/fxml/newCar.fxml"));
          Parent daddy = fxload.load();
          Stage stage = new Stage();
          stage.setTitle("Register a new VehicleDTO");
          stage.setScene(new Scene(daddy));
          stage.show();
      }catch (Exception e){
          e.printStackTrace();
      }
      }
  
  public void fillTable(){
      List&lt;VehicleDTO&gt; vroomys = serviceBoi.fetchVroomList();
  
  
      vehicleModelNameColumn.setCellValueFactory(new PropertyValueFactory&lt;&gt;("charName")); //this is line 159
      vehicleMotorisedColumn.setCellValueFactory(new PropertyValueFactory&lt;&gt;("motor"));
      vehicleConstructionDateColumn.setCellValueFactory(new PropertyValueFactory&lt;&gt;("constructionDate"));
      vehicleCapacityColumn.setCellValueFactory(new PropertyValueFactory&lt;&gt;("capacity"));
      vehiclePlateNumberColumn.setCellValueFactory(new PropertyValueFactory&lt;&gt;("plateNumber"));
      vehiclePowerColumn.setCellValueFactory(new PropertyValueFactory&lt;&gt;("powerKW"));
      vehiclePriceColumn.setCellValueFactory(new PropertyValueFactory&lt;&gt;("rentPrice"));
  
      vehicleTable.setItems(getObservableVrooms(vroomys));
  
  
  
  }
  
  private ObservableList&lt;VehicleDTO&gt; getObservableVrooms(List&lt;VehicleDTO&gt; vehicleList) {
      try {
          ObservableList&lt;VehicleDTO&gt; observableList = FXCollections.observableArrayList(vehicleList);
          return observableList;
      } catch (Exception e) {
          e.printStackTrace();
      }
      return null;
  }
  </code></pre>
  
  <p>}</p>
  
  <p>Which is supposed to fill the Table with variables from the VehicleDTO List. The list itself is filled( I checked) and the VehicleDTO Class looks like this:</p>
  
  <pre><code>public class VehicleDTO {
  private int vid;
  private String charName;
  private int constructionDate;
  private String description;
  private short capacity;
  private String plateNumber;
  private boolean motor;
  private short powerKW;
  private double rentPrice;
  private java.sql.Date entryDate;
  private boolean deleted;
  private String picturePath;
  private List&lt;Licenses&gt; requiredLicenses;
  private java.sql.Timestamp lastEdit;
  
  @Override
  public String toString() {
      return "VehicleDTO{" +
          "vid=" + vid +
          ", charName='" + charName + '\'' +
          ", constructionDate=" + constructionDate +
          ", description='" + description + '\'' +
          ", capacity=" + capacity +
          ", plateNumber='" + plateNumber + '\'' +
          ", motor=" + motor +
          ", powerKW=" + powerKW +
          ", rentPrice=" + rentPrice +
          ", entryDate=" + entryDate +
          ", deleted=" + deleted +
          ", picturePath='" + picturePath + '\'' +
          ", requiredLicenses=" + requiredLicenses +
          '}';
  }
  
  public VehicleDTO(String charName, boolean motor, double rentPrice, Date entryDate, boolean deleted, List&lt;Licenses&gt; requiredLicenses) {
      this.charName = charName;
      this.motor = motor;
      this.rentPrice = rentPrice;
      this.entryDate = entryDate;
      this.deleted = deleted;
      this.requiredLicenses = requiredLicenses;
  }
  </code></pre>
  
  <p>Excluding all of the getter/setter methods. 
  The UIManager Class is connected to this FXML file:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  
  &lt;?import java.lang.*?&gt;
  &lt;?import java.util.*?&gt;
  &lt;?import javafx.scene.control.*?&gt;
  &lt;?import javafx.scene.layout.*?&gt;
  &lt;?import javafx.scene.paint.*?&gt;
  
  &lt;AnchorPane id="AnchorPane" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="532.0" prefWidth="849.0" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/2.2" fx:controller="at.ac.tuwien.sepm.assignment.individual.universe.ui.UIManager"&gt;
    &lt;children&gt;
      &lt;TabPane layoutX="14.0" layoutY="14.0" prefHeight="504.0" prefWidth="821.0" tabClosingPolicy="UNAVAILABLE"&gt;
        &lt;tabs&gt;
          &lt;Tab fx:id="reservationsTab" text="Reservations"&gt;
            &lt;content&gt;
               &lt;AnchorPane id="Content" minHeight="0.0" minWidth="0.0" prefHeight="468.0" prefWidth="821.0"&gt;
                &lt;children&gt;
                  &lt;TableView layoutX="0.0" layoutY="0.0" prefHeight="422.0" prefWidth="821.0"&gt;
                    &lt;columns&gt;
                      &lt;TableColumn maxWidth="5000.0" minWidth="10.0" prefWidth="125.0" text="Customer Name" fx:id="reservationsCustomerNameColumn" /&gt;
                      &lt;TableColumn maxWidth="5000.0" minWidth="10.0" prefWidth="138.0" text="IBAN/Credit Card" fx:id="reservationIbanColumn" /&gt;
                      &lt;TableColumn maxWidth="5000.0" minWidth="10.0" prefWidth="97.0" text=" Status" fx:id="reservationBookingStatusColumn" /&gt;
                      &lt;TableColumn maxWidth="5000.0" minWidth="10.0" prefWidth="138.0" text="Rental Start Date" fx:id="reservationRStartDateColumn" /&gt;
                      &lt;TableColumn maxWidth="5000.0" minWidth="10.0" prefWidth="124.0" text="Rental End Date" fx:id="reservationRentalEndColumn" /&gt;
                      &lt;TableColumn maxWidth="5000.0" minWidth="10.0" prefWidth="109.0" text="Total Price" fx:id="reservationsTotalPriceColumn" /&gt;
                    &lt;/columns&gt;
                  &lt;/TableView&gt;
                  &lt;Button id="reservationEdit" fx:id="reservationEditButton" layoutX="0.0" layoutY="434.0" mnemonicParsing="false" text="Edit" /&gt;
                  &lt;Button fx:id="reservationNewButton" layoutX="72.0" layoutY="434.0" mnemonicParsing="false" onAction="#openNewCarWindow" text="New" /&gt;
                  &lt;Button fx:id="reservationSearchButton" layoutX="754.0" layoutY="434.0" mnemonicParsing="false" text="Search" /&gt;
                  &lt;Button fx:id="reservationDeleteButton" layoutX="149.0" layoutY="434.0" mnemonicParsing="false" text="Delete" /&gt;
                &lt;/children&gt;
              &lt;/AnchorPane&gt;
             &lt;/content&gt;
          &lt;/Tab&gt;
          &lt;Tab fx:id="vehiclesTab" text="Vehicles"&gt;
            &lt;content&gt;
               &lt;AnchorPane id="Content" minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0"&gt;
                &lt;children&gt;
                  &lt;TableView fx:id="vehicleTable" layoutX="0.0" layoutY="0.0" prefHeight="419.0" prefWidth="821.0"&gt;
                    &lt;columns&gt;
                      &lt;TableColumn maxWidth="5000.0" minWidth="10.0" prefWidth="104.0" text="Model Name" fx:id="vehicleModelNameColumn" /&gt;
                      &lt;TableColumn maxWidth="5000.0" minWidth="10.0" prefWidth="136.0" text="Construction Date" fx:id="vehicleConstructionDateColumn" /&gt;
                      &lt;TableColumn prefWidth="75.0" text="Capacity" fx:id="vehicleCapacityColumn" /&gt;
                      &lt;TableColumn maxWidth="5000.0" minWidth="10.0" prefWidth="118.0" text="Plate Number" fx:id="vehiclePlateNumberColumn" /&gt;
                      &lt;TableColumn maxWidth="5000.0" minWidth="10.0" prefWidth="125.0" text="Per Hour Price" fx:id="vehiclePriceColumn" /&gt;
                      &lt;TableColumn maxWidth="5000.0" minWidth="10.0" prefWidth="105.0" text="Power(KW)" fx:id="vehiclePowerColumn" /&gt;
                      &lt;TableColumn maxWidth="5000.0" minWidth="10.0" prefWidth="104.0" text="Motorised" fx:id="vehicleMotorisedColumn" /&gt;
                    &lt;/columns&gt;
                  &lt;/TableView&gt;
                  &lt;Button fx:id="vehicleEditButton" layoutX="0.0" layoutY="434.0" mnemonicParsing="false" text="Edit" /&gt;
                  &lt;Button fx:id="vehicleNewButton" layoutX="72.0" layoutY="434.0" mnemonicParsing="false" text="New" /&gt;
                  &lt;Button fx:id="vehicleDeleteButton" layoutX="148.0" layoutY="434.0" mnemonicParsing="false" text="Delete" /&gt;
                  &lt;Button fx:id="vehicleSearchButton" layoutX="755.0" layoutY="434.0" mnemonicParsing="false" text="Search" /&gt;
                 &lt;/children&gt;
               &lt;/AnchorPane&gt;
            &lt;/content&gt;
          &lt;/Tab&gt;
        &lt;/tabs&gt;
      &lt;/TabPane&gt;
    &lt;/children&gt;
  &lt;/AnchorPane&gt;
  </code></pre>
  
  <p>This is the error I am getting:</p>
  
  <pre><code>    Exception in Application start method
  java.lang.reflect.InvocationTargetException
      at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
  at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  at java.base/java.lang.reflect.Method.invoke(Method.java:564)
  at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:473)
  at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:372)
  at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
  at      java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  at java.base/java.lang.reflect.Method.invoke(Method.java:564)
      at java.base/sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:945)
  Caused by: java.lang.RuntimeException: Exception in Application start method
  at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication1(Lau   ncherImpl.java:973)
  at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:198)
  at java.base/java.lang.Thread.run(Thread.java:844)
  Caused by: java.lang.NullPointerException
  at at.ac.tuwien.sepm.assignment.individual.universe.ui.UIManager.fillTable(UIManager.java:159)
  at at.ac.tuwien.sepm.assignment.individual.application.MainApplication.start(MainApplication.java:49)
  at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:919)
  at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$11(PlatformImpl.java:449)
  at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$9(PlatformImpl.java:418)
  at java.base/java.security.AccessController.doPrivileged(Native Method)
  at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:417)
  at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
  at javafx.graphics/com.sun.glass.ui.gtk.GtkApplication._runLoop(Native Method)
  at javafx.graphics/com.sun.glass.ui.gtk.GtkApplication.lambda$runLoop$11(GtkApplication.java:277)
  ... 1 more
  Exception running application at.ac.tuwien.sepm.assignment.individual.application.MainApplication
  </code></pre>
  
  <p>I've checked that the list is filled with appropriate values and I've tried using callback to fill the list. Line 159, which is in this error message, is the line </p>
  
  <pre><code>vehicleModelNameColumn.setCellValueFactory(new PropertyValueFactory&lt;&gt;("charName"));
  </code></pre>
  
  <p>within the fillTable() method.
  I am absolutely stuck please help. </p>