-1

Building an application in JavaFX, using a table to populate customer name and id and then added a button that launches another form once a customer name is selected from the table. I am getting errors in.

I have tried to change the name populateCustomerAllName, tried to change the return type

 @FXML 
public void handleAddButton() {
    if(customerAllTable.getSelectionModel().getSelectedItem() != null) {
        selectedCustomer = customerAllTable.getSelectionModel().getSelectedItem();
    } else {
        return;
    }
    Dialog<ButtonType> dialog = new Dialog();
    dialog.initOwner(appointmentMain.getScene().getWindow());
    FXMLLoader fxmlLoader = new FXMLLoader();
    fxmlLoader.setLocation(getClass().getResource("AppointmentAdd.fxml"));
    try {
        dialog.getDialogPane().setContent(fxmlLoader.load());
    } catch(IOException e) {
        System.out.println("AppointmentAdd Error: " + e.getMessage());
    }
    ButtonType save = new ButtonType("Save", ButtonBar.ButtonData.OK_DONE);
    dialog.getDialogPane().getButtonTypes().add(save);
    dialog.getDialogPane().getButtonTypes().add(ButtonType.CANCEL);
    AppointmentAddController controller = fxmlLoader.getController();


//error with populating .getCustomerAllName         controller.populateCustomerAllName(selectedCustomer.getCustomerAllName());
    dialog.showAndWait().ifPresent((response -> {
        if(response == save) {
            if(controller.handleAddAppointment(selectedCustomer.getCustomerAllId())) {
                monthAptTable.setItems(AppointmentDB.getMonthlyAppointments(selectedCustomer.getCustomerAllId()));
                weekAptTable.setItems(AppointmentDB.getWeeklyAppoinments(selectedCustomer.getCustomerAllId()));
            } else {
                Alert alert = new Alert(Alert.AlertType.ERROR);
                alert.setTitle("Error");
                alert.setHeaderText("Add Appointment Error");
                alert.setContentText(controller.displayErrors());
                alert.showAndWait().ifPresent((response2 -> {
                    if(response2 == ButtonType.OK) {
                        handleAddButton();
                    }
                }));
            }
        }
    }));







public void populateCustomerAllName(String name) {
    customerAllName.setText(name);
}







Caused by: java.lang.NullPointerException
at   views.AppointmentAddController.populateCustomerAllName(AppointmentAddController.java:170)
at views.AppointmentMainController.handleAddButton(AppointmentMainController.java:155)

Expected results are when clicking on the addAppointment button the customers name is populated into the customer field.

Daniel Strong
  • 203
  • 3
  • 7
  • 20

1 Answers1

0

needed to update the fxml tag fx:id="customerAllName"

Daniel Strong
  • 203
  • 3
  • 7
  • 20