im trying to learn about JavaFX and bumped into NullPointerException for Controller. Meaning everytime i use the instance of controller, eclipse show the Exception. I have read severals similar questions but non of this solved my case.
Here is the code snippet that caused the Exception
public GuiController (Stage a) throws IOException {
this.priStage = a;
FXMLLoader fxLoader = new FXMLLoader(getClass().getClassLoader().getResource("View/OverviewWindow.fxml"));
overviewController = fxLoader.getController();
overviewController.getRefreshButton().setText("Oh no"); **// When i remove this line everything works fine!**
Parent root = fxLoader.load();
priStage.setScene(new Scene(root));
priStage.show();
}
Here is my Controller class, basicly nothing :
public class OverviewWindow implements Initializable {
@FXML TextField searchTextField;
@FXML
private Button standardButton;
@FXML
private Button refreshButton;
@FXML
private RadioButton mitArchivRadioButton;
@FXML
private RadioButton nurArchivButton;
@Override
public void initialize(URL a, ResourceBundle b) {
}
public OverviewWindow() {
}
}
my stack trace
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NullPointerException
at Controller.GuiController.<init>(GuiController.java:31)
at Controller.Controller.init(Controller.java:33)
at main.start(main.java:24)
Can someone help me ? I read about this problem for days and tried manyway to set the controller right but couldnt do it. Thanks.