0

I have #closeMethod that gets called when user goes to File->Exit in my app:

 public void closeProgram(){

    int choice = JOptionPane.showConfirmDialog(null, "Do You want to exit the program ? ", "Exit Panel", JOptionPane.YES_NO_OPTION);

    if(choice == JOptionPane.YES_OPTION){                    

        Thread ending = new Thread(){

            @Override
            public void run(){

                aboutDevelopers();
            }

        };

        ending.start();        
        System.exit(0);                        
    }

}

And I have an #aboutDevelopers method here: When it is called through File->AboutDevelopers, it shows up well but on closeProgram() , it crashes.

public void aboutDevelopers(){

    try {

        Stage stage = new Stage();
        Parent root = FXMLLoader.load(getClass().getResource("AboutUsLayout.fxml"));

        Scene scene = new Scene(root);

        stage.setTitle("About Developers");            
        stage.setScene(scene);
        stage.setResizable(false);
        stage.show();             

    } catch (IOException ex) {
        Logger.getLogger(FirstLayoutController.class.getName()).log(Level.SEVERE, null, ex);

    }    

}

I want the programme to wait for user to close the AboutUsLayout window and then exit out.

My stack trace:

Executing D:\Tilak\BeansProjects\WhatsThePassword\dist\run1156653616\WhatsThePassword.jar using platform C:\Program Files\Java\jdk1.8.0_05\jre/bin/java
Exception in thread "Thread-6" java.lang.IllegalStateException: Not on FX application thread; currentThread = Thread-6
    at com.sun.javafx.tk.Toolkit.checkFxUserThread(Toolkit.java:210)
    at com.sun.javafx.tk.quantum.QuantumToolkit.checkFxUserThread(QuantumToolkit.java:393)
    at javafx.stage.Stage.<init>(Stage.java:233)
    at javafx.stage.Stage.<init>(Stage.java:219)
    at password.FirstLayoutController.aboutDevelopers(FirstLayoutController.java:470)
    at password.FirstLayoutController$1.run(FirstLayoutController.java:412)
Tilak Madichetti
  • 4,110
  • 5
  • 34
  • 52
  • 1
    http://stackoverflow.com/questions/17850191/why-am-i-getting-java-lang-illegalstateexception-on-javafx – Reimeus Oct 15 '16 at 15:33
  • Additionally, you should only show a `JOptionPane` on the AWT Event Dispatch thread. It is much better not to mix Swing and JavaFX; use a JavaFX [`Alert`](http://docs.oracle.com/javase/8/javafx/api/javafx/scene/control/Alert.html) instead. – James_D Oct 15 '16 at 15:36

0 Answers0