When I have a controller that accesses the controls of the FXML through @FXML
, then I don't neeed to initialize them. I can just access them (result.setText("test")
for example), as I can see in various examples. For some reason, that doesn't work for me and I can't find the reason. Can someone tell me the reason please?
public class WiderstandController implements Initializable {
@FXML
private TextField input;
@FXML
private Label result;
@FXML
private Button btn;
@FXML
private void berechne() {
result.setText("test");
System.out.println(result.getText());
}
@Override
public void initialize(URL location, ResourceBundle resources) {
}
}
And here is the relevant FXML part (inside a Pane
):
fx:controller="widerstand.WiderstandController"
Can you see what is wrong or do you need more? I don't want to spam everything here if we can find it already in that class.
EDIT: by not being able to access I mean that I get NullPointerException
.