Your posted code is incomplete. The FXMLLoader is loading the "AddUser.fxml" file. It also calling the initialize method of the controller. But the nullpointerexception appears at a line number 144 in updateUsersList() method. Check that line. And you may want to change the controller class of "AddUser.fxml" to other one than FileSharingController.
As per comment,
Does each Layout need a seperate controller?
Technically no, but semantically yes. If you set the same fx:controller
in different FXML files then you will end up with multiple instances of that controller for every FXML file being loaded. If you use FXMLLoader.setController()
among with FXMLLoader.setRoot()
where the FXML files include fx:root
instead of fx:controller
then you will end up with only one instance of the controller which its initialize()
method will be called separately for every FXML file being loaded. In both cases, however, each FXML file will semantically deal with only some part of the controller, i.e. init, inject, set, manipulate the parts it is interested in. IMO the FXML files should have no mutual domain, and if have then they must use normal java messaging mechanism through their own controllers. So having another AddUserController class will be more modular, maintainable and less headaches.