title: Starting JavaFX from Main method of class which doesn't extend Application
body: <p>I'm having problem to start a JavaFX Application from a Main method of a class which doesn't extend <code>javafx.application.Application</code></p>
  
  <p>In my application there is the <code>MainApp.java</code> which should start the overriden method <code>start()</code> in the <code>MainUIController.java</code>, which extends <code>Applciation</code></p>
  
  <p>When I start the Main method from the <code>MainUIController.java</code> everything works fine.</p>
  
  <p><strong>MainApp.java</strong></p>
  
  <pre><code>public class MainApp {
  
      public static void main(String[] args) {
          PersonJDBCTemplate jdbc = connect();
          MainUIController mUIc = new MainUIController(jdbc);
          mUIc.start(new Stage());
  
      }
  
      public static PersonJDBCTemplate connect() {
          ApplicationContext context = new ClassPathXmlApplicationContext(
                  "Beans.xml");
          PersonJDBCTemplate personJDBCTemplate = (PersonJDBCTemplate) context
                  .getBean("personJDBCTemplate");
          return personJDBCTemplate;
      }
  }
  </code></pre>
  
  <p><strong>MainUIController.java</strong></p>
  
  <pre><code>public class MainUIController extends Application {
  
      private Stage stage;
      // private User loggedUser;
      private final double MINIMUM_WINDOW_WIDTH = 800.0;
      private final double MINIMUM_WINDOW_HEIGHT = 570.0;
      private String version = "0.6";
      private PersonJDBCTemplate jdbc;
  
      public MainUIController(PersonJDBCTemplate jdbc) {
          this.jdbc = jdbc;
  
      }
  
      @Override
      public void start(Stage primaryStage) {
          try {
              stage = primaryStage;
              stage.setTitle("Sharp");
              stage.setMinWidth(MINIMUM_WINDOW_WIDTH);
              stage.setMinHeight(MINIMUM_WINDOW_HEIGHT);
              stage.setResizable(false);
              gotoLogin();
              primaryStage.show();
          } catch (Exception ex) {
              Logger.getLogger(MainUIController.class.getName()).log(
                      Level.SEVERE, null, ex);
          }
      }
  
      public void gotoLogin() {
          try {
              LoginController login = (LoginController) replaceSceneContent("/fxml/Login.fxml");
              login.setApp(this);
          } catch (Exception ex) {
              Logger.getLogger(MainUIController.class.getName()).log(
                      Level.SEVERE, null, ex);
          }
      }
  }
  </code></pre>
  
  <p><strong>After running the <em>MainApp</em>, I get the following Error :</strong></p>
  
  <pre><code>Exception in thread "main" java.lang.ExceptionInInitializerError
  at javafx.stage.Window.&lt;init&gt;(Window.java:1110)
  at javafx.stage.Stage.&lt;init&gt;(Stage.java:236)
  at javafx.stage.Stage.&lt;init&gt;(Stage.java:224)
  at ch.kit.sharp.main.MainApp.main(MainApp.java:15)
  Caused by: java.lang.IllegalStateException: This operation is permitted on the event thread only; currentThread = main
  at com.sun.glass.ui.Application.checkEventThread(Application.java:445)
  at com.sun.glass.ui.Screen.setEventHandler(Screen.java:245)
  at com.sun.javafx.tk.quantum.QuantumToolkit.setScreenConfigurationListener(QuantumToolkit.java:600)
  at javafx.stage.Screen.&lt;clinit&gt;(Screen.java:80)
  ... 4 more
  </code></pre>