JavaRush /Java Blog /Random-TW /JavaFX 使用 TextField 和 TableView 元素。
Artemka58_1
等級 21

JavaFX 使用 TextField 和 TableView 元素。

在 Random-TW 群組發布
請幫我弄清楚。有幾個班。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