0

I am having trouble instantiating my controller class. When I try to make an instance it comes up null. I have been looking into previous posts about this and the closest I can get is:

Parent root = FXMLLoader.load(getClass().getResource("/gui/GuiFXML.fxml"));
scene = new Scene(root,1024,768);
stage.setScene(scene);
stage.setTitle("Proving Grounds");
stage.show();
GuiController controller = new GuiController();
controller.setTextArea("things and stuff");

Found these related questions but they seem to add more errors rather than fix anything.

FXMLLoader get controller returns null

JavaFX controller is always null

Community
  • 1
  • 1

1 Answers1

1
FXMLLoader loader = new FXMLLoader(getClass().getResource("/gui/GuiFXML.fxml"));
...
Parent root = loader.load();
...
GuiController controller = loader.getController();
...
Rafael Guillen
  • 1,343
  • 10
  • 25
  • Awesome thank you! it did make me cast loader.load() to parent. is that ok? it became Parent root = (Parent) loader.load(); – pieAre5quare Oct 29 '14 at 14:07