JavaRush /Java 博客 /Random-ZH /JavaFX 使用 TextField 和 TableView 元素。
Artemka58_1
第 21 级

JavaFX 使用 TextField 和 TableView 元素。

已在 Random-ZH 群组中发布
请帮我弄清楚。有几个班。Employee 类是一个可以包含 SimpleStringProperty 类型数据的对象。有一个 fxml 文件,其中包含用于添加/更改员工对象列表的窗口布局。AddEmployee 类是 fxml 文件的事件处理程序。将所选对象中的文本添加到 TextField 时,Employees 开始咒骂。如果单独看,数据是从对象中“提取”出来的,但无法插入到 TextField 中。处理程序代码: @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()); } 对象代码: 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(); } 错误:Caused by: java.lang.NullPointerException at controllers.AddEmployee.setEmployees(AddEmployee.java:39) at controllers.EmployeesController.onButtonPressedAction(EmployeesController.java:89)指向tf_employee.setText(employees.getId_eml()); 窗口本身:JavaFX 使用 TextField 和 TableView 元素。 - 1
评论
TO VIEW ALL COMMENTS OR TO MAKE A COMMENT,
GO TO FULL VERSION