I'm having trouble appending a username to a listview. I create users in one controller, while calling a method from another controller which appends the newly created username to a listview, but there's multiple runtime errors.
Method of adding users in the first controller:
void addUser(ActionEvent event) {
User user = new User();
user.setUsername(newUserField.getText());
user.setPassword(newPassField.getText());
UserDAO theDAO = new UserDAO();
theDAO.createUser(user);
MainPanelAdminController mc = new MainPanelAdminController();
mc.appendList(user.getUsername())
}
And this is the append method in the second controller:
void appendList(String username) {
Label lbl = new Label(username);
ObservableList<Label> items = FXCollections.observableArrayList(lbl);
listView.setItems(items);
}
Note: The setUsername()
, setPassword()
, createUser()
and getUsername()
methods are all working; the issue comes about at listView.setItems(items)
- I added debugging lines to check.
Right now when I add a user it gives this error:
Caused by: java.lang.NullPointerException at Admin.panel.MainPanelAdminController.appendList(MainPanelAdminController.java:61) at Admin.panel.createUserController.addUser(createUserController.java:35) ... 58 more
Line 61:
listView.setItems(items);
Line 35:mc.appendList(user.getUsername());