0

So I have this block of code:

public class UIManager {
    private MainMenuService serviceBoi;
    public UIManager(){
        serviceBoi = new MainMenuService();
    }

@FXML
private ResourceBundle resources;

@FXML
private URL location;

@FXML
private TableColumn<?, ?> reservationBookingStatusColumn;

@FXML
private Button reservationDeleteButton;

@FXML
private Button reservationEditButton;

@FXML
private TableColumn<?, ?> reservationIbanColumn;

@FXML
private Button reservationNewButton;

@FXML
private TableColumn<?, ?> reservationRStartDateColumn;

@FXML
private TableColumn<?, ?> reservationRentalEndColumn;

@FXML
private Button reservationSearchButton;

@FXML
private TableColumn<?, ?> reservationsCustomerNameColumn;

@FXML
private Tab reservationsTab;

@FXML
private TableColumn<?, ?> reservationsTotalPriceColumn;

@FXML
private TableColumn<VehicleDTO, Short> vehicleCapacityColumn;

@FXML
private TableColumn<VehicleDTO, Integer> vehicleConstructionDateColumn;

@FXML
private Button vehicleDeleteButton;

@FXML
private Button vehicleEditButton;

@FXML
private TableColumn<VehicleDTO, String> vehicleModelNameColumn;

@FXML
private TableColumn<VehicleDTO, Boolean> vehicleMotorisedColumn;

@FXML
private Button vehicleNewButton;

@FXML
private TableColumn<VehicleDTO, String> vehiclePlateNumberColumn;

@FXML
private TableColumn<VehicleDTO, Integer> vehiclePowerColumn;

@FXML
private TableColumn<VehicleDTO, Double> vehiclePriceColumn;

@FXML
private Button vehicleSearchButton;

@FXML
private TableView<VehicleDTO> 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<VehicleDTO> vroomys = serviceBoi.fetchVroomList();


    vehicleModelNameColumn.setCellValueFactory(new PropertyValueFactory<>("charName")); //this is line 159
    vehicleMotorisedColumn.setCellValueFactory(new PropertyValueFactory<>("motor"));
    vehicleConstructionDateColumn.setCellValueFactory(new PropertyValueFactory<>("constructionDate"));
    vehicleCapacityColumn.setCellValueFactory(new PropertyValueFactory<>("capacity"));
    vehiclePlateNumberColumn.setCellValueFactory(new PropertyValueFactory<>("plateNumber"));
    vehiclePowerColumn.setCellValueFactory(new PropertyValueFactory<>("powerKW"));
    vehiclePriceColumn.setCellValueFactory(new PropertyValueFactory<>("rentPrice"));

    vehicleTable.setItems(getObservableVrooms(vroomys));



}

private ObservableList<VehicleDTO> getObservableVrooms(List<VehicleDTO> vehicleList) {
    try {
        ObservableList<VehicleDTO> observableList = FXCollections.observableArrayList(vehicleList);
        return observableList;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}

}

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:

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<Licenses> 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<Licenses> requiredLicenses) {
    this.charName = charName;
    this.motor = motor;
    this.rentPrice = rentPrice;
    this.entryDate = entryDate;
    this.deleted = deleted;
    this.requiredLicenses = requiredLicenses;
}

Excluding all of the getter/setter methods. The UIManager Class is connected to this FXML file:

<?xml version="1.0" encoding="UTF-8"?>

<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.paint.*?>

<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">
  <children>
    <TabPane layoutX="14.0" layoutY="14.0" prefHeight="504.0" prefWidth="821.0" tabClosingPolicy="UNAVAILABLE">
      <tabs>
        <Tab fx:id="reservationsTab" text="Reservations">
          <content>
             <AnchorPane id="Content" minHeight="0.0" minWidth="0.0" prefHeight="468.0" prefWidth="821.0">
              <children>
                <TableView layoutX="0.0" layoutY="0.0" prefHeight="422.0" prefWidth="821.0">
                  <columns>
                    <TableColumn maxWidth="5000.0" minWidth="10.0" prefWidth="125.0" text="Customer Name" fx:id="reservationsCustomerNameColumn" />
                    <TableColumn maxWidth="5000.0" minWidth="10.0" prefWidth="138.0" text="IBAN/Credit Card" fx:id="reservationIbanColumn" />
                    <TableColumn maxWidth="5000.0" minWidth="10.0" prefWidth="97.0" text=" Status" fx:id="reservationBookingStatusColumn" />
                    <TableColumn maxWidth="5000.0" minWidth="10.0" prefWidth="138.0" text="Rental Start Date" fx:id="reservationRStartDateColumn" />
                    <TableColumn maxWidth="5000.0" minWidth="10.0" prefWidth="124.0" text="Rental End Date" fx:id="reservationRentalEndColumn" />
                    <TableColumn maxWidth="5000.0" minWidth="10.0" prefWidth="109.0" text="Total Price" fx:id="reservationsTotalPriceColumn" />
                  </columns>
                </TableView>
                <Button id="reservationEdit" fx:id="reservationEditButton" layoutX="0.0" layoutY="434.0" mnemonicParsing="false" text="Edit" />
                <Button fx:id="reservationNewButton" layoutX="72.0" layoutY="434.0" mnemonicParsing="false" onAction="#openNewCarWindow" text="New" />
                <Button fx:id="reservationSearchButton" layoutX="754.0" layoutY="434.0" mnemonicParsing="false" text="Search" />
                <Button fx:id="reservationDeleteButton" layoutX="149.0" layoutY="434.0" mnemonicParsing="false" text="Delete" />
              </children>
            </AnchorPane>
           </content>
        </Tab>
        <Tab fx:id="vehiclesTab" text="Vehicles">
          <content>
             <AnchorPane id="Content" minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0">
              <children>
                <TableView fx:id="vehicleTable" layoutX="0.0" layoutY="0.0" prefHeight="419.0" prefWidth="821.0">
                  <columns>
                    <TableColumn maxWidth="5000.0" minWidth="10.0" prefWidth="104.0" text="Model Name" fx:id="vehicleModelNameColumn" />
                    <TableColumn maxWidth="5000.0" minWidth="10.0" prefWidth="136.0" text="Construction Date" fx:id="vehicleConstructionDateColumn" />
                    <TableColumn prefWidth="75.0" text="Capacity" fx:id="vehicleCapacityColumn" />
                    <TableColumn maxWidth="5000.0" minWidth="10.0" prefWidth="118.0" text="Plate Number" fx:id="vehiclePlateNumberColumn" />
                    <TableColumn maxWidth="5000.0" minWidth="10.0" prefWidth="125.0" text="Per Hour Price" fx:id="vehiclePriceColumn" />
                    <TableColumn maxWidth="5000.0" minWidth="10.0" prefWidth="105.0" text="Power(KW)" fx:id="vehiclePowerColumn" />
                    <TableColumn maxWidth="5000.0" minWidth="10.0" prefWidth="104.0" text="Motorised" fx:id="vehicleMotorisedColumn" />
                  </columns>
                </TableView>
                <Button fx:id="vehicleEditButton" layoutX="0.0" layoutY="434.0" mnemonicParsing="false" text="Edit" />
                <Button fx:id="vehicleNewButton" layoutX="72.0" layoutY="434.0" mnemonicParsing="false" text="New" />
                <Button fx:id="vehicleDeleteButton" layoutX="148.0" layoutY="434.0" mnemonicParsing="false" text="Delete" />
                <Button fx:id="vehicleSearchButton" layoutX="755.0" layoutY="434.0" mnemonicParsing="false" text="Search" />
               </children>
             </AnchorPane>
          </content>
        </Tab>
      </tabs>
    </TabPane>
  </children>
</AnchorPane>

This is the error I am getting:

    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

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

vehicleModelNameColumn.setCellValueFactory(new PropertyValueFactory<>("charName"));

within the fillTable() method. I am absolutely stuck please help.

borobosis
  • 1
  • 1
  • something wrong in the code you are not showing .. ;) Please read http://stackoverflow.com/help/mcve and act accordingly. – kleopatra Apr 05 '18 at 09:42
  • One of the variables/fields you use in the `fillTable` method is `null`. It's on the line 159. We don't know which line is it but you should easily see it in your IDE. – lexicore Apr 05 '18 at 09:46
  • I edited the post to make sure it was understanded that line 159 is within the post. – borobosis Apr 05 '18 at 11:47
  • why don't you simply provide a MCVE? You need it for yourself to find the cause of the error anyway ... Anyway, the stacktrace tells you exactly what's wrong: vehicleWhateverColumn is null - probably not inserted (missing fxml annotation?) - can't tell because it's code you are _not_ showing ... – kleopatra Apr 05 '18 at 11:50
  • OK so I think this is all the code that has anything to do with the problem. Please look through it once again – borobosis Apr 05 '18 at 12:03
  • it's not minimal (don't need all the other columns/buttons), not complete (doesn't include where/how fillTable is called), not verifiable (contains references to classes that are not available) ... please do _exactly_ what the help page describes ... the idea is, that you create a new program with contains just the stuff that exposes the problem, not more and not less. While preparing it and comparing with the original, you most probably can find the error yourself. If not, I (and/or others) can throw your example into an IDE and see where it really breaks. – kleopatra Apr 05 '18 at 15:13

0 Answers0