PropertyValueProperty unable to retrieve property

692 views Asked by At

I am having trouble populating a TableView with data. I am not using proper properties I am just trying to retrieve the property from my get...() method for every field in my Client class.

Here is my client class:

public class Client {

    private Integer ID;
    public String firstName;
    public String lastName;
    public String email;
    public String phoneNumber;
    public Integer age;

    public Client() {}
    public Client(String firstName, String lastName, String email, String phoneNumber, int age) {
        this.firstName = firstName;
        this.lastName = lastName;
        this.email = email;
        this.phoneNumber = phoneNumber;
        this.age = age;
    }

    public void setID(Integer ID) {
        this.ID = ID;
    }

    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public void setPhoneNumber(String phoneNumber) {
        this.phoneNumber = phoneNumber;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    public Integer getID() {
        return ID;
    }

    public String getFirstName() {
        return firstName;
    }

    public String getLastName() {
        return lastName;
    }

    public String getEmail() {
        return email;
    }

    public String getPhoneNumber() {
        return phoneNumber;
    }

    public Integer getAge() {
        return age;
    }


    @Override
    public String toString(){
        return "ID: " + this.ID + " First Name: " +
                this.firstName + " Last Name: " + this.lastName + " Email: " +
                this.email + " Phone: " + this.phoneNumber + " Age: " + this.age;
    }

}

And here is my controller where I am trying to populate the TableView:

public class ClientWindowController implements Initializable {

    private final String fxml = "add_client_window.fxml";
    private final String fxml1 = "update_client_window.fxml";
    private final String fxml2 = "remove_client_window.fxml";

    @FXML
    Button addClient;

    @FXML
    Button updateClient;

    @FXML
    Button removeClient;

    @FXML
    TableView<Client> clientTableView;

    @FXML
    private TableColumn<Client, String> firstNameColumn;

    @FXML
    private TableColumn<Client, String> lastNameColumn;

    @FXML
    private TableColumn<Client, String> phoneNumberColumn;

    @FXML
    private TableColumn<Client, String> emailColumn;

    @FXML
    private TableColumn<Client, Integer> ageColumn;

    @FXML
    private TableColumn<Client, Integer> IDColumn;

    ObservableList<Client> observableList = FXCollections.observableArrayList();

    @FXML
    public void openAddClientWindow() throws IOException {
        App.openWindow(fxml, 500, 500);
    }

    @FXML
    public void openUpdateClientWindow() throws IOException {
        App.openWindow(fxml1, 500, 500);
    }

    @FXML
    public void openRemoveClientWindow() {
        App.openWindow(fxml2, 250, 200);
    }

    @Override
    public void initialize(URL url, ResourceBundle resourceBundle) {

        ClientDAO clientDAO = new ClientDAO();
        List<Client> clients = clientDAO.findAll();
        observableList = FXCollections.observableArrayList(clients);



        IDColumn.setCellValueFactory(new PropertyValueFactory<>("ID"));
        firstNameColumn.setCellValueFactory(new PropertyValueFactory<Client, String>("firstName"));
        lastNameColumn.setCellValueFactory(new PropertyValueFactory<>("lastName"));
        emailColumn.setCellValueFactory(new PropertyValueFactory<>("email"));
        phoneNumberColumn.setCellValueFactory(new PropertyValueFactory<>("phoneNumber"));
        ageColumn.setCellValueFactory(new PropertyValueFactory<>("age"));

        clientTableView.setItems(observableList);

    }
}

The error im getting:

Apr 22, 2021 12:58:46 AM javafx.scene.control.cell.PropertyValueFactory getCellDataReflectively
WARNING: Can not retrieve property 'ID' in PropertyValueFactory: javafx.scene.control.cell.PropertyValueFactory@241b95d with provided class type: class org.example.model.Client
java.lang.RuntimeException: java.lang.IllegalAccessException: module javafx.base cannot access class org.example.model.Client (in module org.example) because module org.example does not open org.example.model to javafx.base
0

There are 0 answers