In addition to what Nejinx said, you must not directly call your start()
, always call launch()
, because it sets up the JavaFX environment, including creation of stage
and calls start()
passing the stage as an parameter to it.
The docs has a note specially stating this
NOTE: This method is called on the JavaFX Application Thread
The launch()
can be called from any class, taking into consideration if the class is directly not extending javafx.application.Application
, then you must pass the class extending it as an argument to the launch method.
For example, consider you have a class JavaFXMain
which extends Application
class JavaFXMain extends Application {...}
You can use any other class, to start the JavaFX Application.
class Main {
...
public void someMethod() {
...
JavaFXMain.launch(JavaFXMain.class); // Launch the JavaFX application
...
}
}
In your case, you can try something like this inside the main method of MainApp
:
// You may remove args if you don't intend to pass any arguments
MainUIController.launch(MainUIController.class, args)