JavaRush /Java Blog /Random EN /JavaFX working with TextField and TableView element.
Artemka58_1
Level 21

JavaFX working with TextField and TableView element.

Published in the Random EN group
Please help me figure it out. There are several classes. The Employee class is an object that can contain data of the SimpleStringProperty type. There is an fxml file that contains the window layout for adding/changing the list of Employees objects. The AddEmployee class is an event handler for the fxml file. When adding text to the TextField from the selected object, Employees starts swearing. If you look separately, the data is “extracted” from the object, but it cannot be inserted into the TextField. Handler code: @FXML private TextField tf_employee; @FXML private TextField tf_surname; @FXML private TextField tf_name; @FXML private TextField tf_patronymic; @FXML private TextField tf_post; Employees employees; public void setEmployees(Employees employees) { if (employees == null){ return; } this.employees = employees; tf_employee.setText(employees.getId_eml()); tf_employee.setText(employees.getId_eml().toString()); tf_surname.setText(employees.getSurname_empl()); tf_name.setText(employees.getName_empl().toString()); tf_patronymic.setText(employees.getPathronymic_empl()); tf_post.setText(employees.getPost_empl()); } Object code: private SimpleStringProperty id_eml = new SimpleStringProperty(""); private SimpleStringProperty surname_empl = new SimpleStringProperty(""); private SimpleStringProperty name_empl = new SimpleStringProperty(""); private SimpleStringProperty pathronymic_empl = new SimpleStringProperty(""); private SimpleStringProperty post_empl = new SimpleStringProperty(""); public Employees(){} public Employees(String id_empl, String surname_empl, String name_empl, String pathronymic_empl, String post_empl) { this.id_eml = new SimpleStringProperty(id_empl); this.surname_empl = new SimpleStringProperty(surname_empl); this.name_empl = new SimpleStringProperty(name_empl); this.pathronymic_empl = new SimpleStringProperty(pathronymic_empl); this.post_empl = new SimpleStringProperty(post_empl); } public String getId_eml() { return id_eml.get(); } Error: Caused by: java.lang.NullPointerException at controllers.AddEmployee.setEmployees(AddEmployee.java:39) at controllers.EmployeesController.onButtonPressedAction(EmployeesController.java:89)points to tf_employee.setText(employees.getId_eml()); the window itself:JavaFX working with TextField and TableView element.  - 1
Comments
TO VIEW ALL COMMENTS OR TO MAKE A COMMENT,
GO TO FULL VERSION