Reputation: 183
I used some commands for getting the controller of a fxml file. at first I used an address like this:
fx:controller="PersonOverviewController"
and the code in main class was like this
FXMLLoader loader = new FXMLLoader();
loader.setLocation(MainApp.class.getResource("view/PersonOverview.fxml"));
AnchorPane ap = loader.load();
PersonOverviewController pc = loader.getController();
pc.setTableContent(this);
but it doesn't work. in another attempt, I changed the
fx:controller="address.view.PersonOverviewController"
and this time it worked. Why this is the case?
Upvotes: 0
Views: 30
Reputation: 82461
FXMLLoader
needs the binary name of the controller class to be specified. If the package of your PersonOverviewController
is address.view
you therefore have to include it in the attribute value.
FXMLLoader
basically creates the controller instance like this, if no controller factory is set:
String fxController = ...
Class controllerClass = getClassLoader().loadClass(fxController);
Object controller = controllerClass.newInstance();
Upvotes: 3