I'm a beginner with javafx and I'm trying for the first time to use the builder scene. I built my scene and I can display it without any problem. I applied the instructions of this post to interact with the fxml file:Accessing FXML controller class
Here is my code :
public class View extends Application {
static MyController myControllerHandle;
@Override
public void start(Stage primaryStage) throws Exception {
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("/resources/foo.fxml"));
Parent p = fxmlLoader.load();
MyController fooController = fxmlLoader.getController();
Scene scene = new Scene(p);
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args){
Application.launch(View.class,args);
}}
The scene is displayed but the controller is null. I found some posts about it but none of them solved my problem.
Post about it :
It's probably a stupid mistake but I've been stuck on it for a long time... Thank you in advance
EDIT :
For the beginner here is the solution: Add the controller class in the fxml file.