How to avoid Not on FX application thread; currentThread = JavaFX Application Thread error?

Calling

Platform.runLater(new Runnable(){
// ...
});

will fix it.


This happened with me when i was modifying UI element from task in javafx 2 like listview elements.A Task Which Modifies The Scene Graph helped me to solve the issue i.e. updating UI elements by

 final ListView<String> group = new ListView ();

 Task<Void> task = new Task<Void>() {

     @Override protected Void call() throws Exception {

         group.getItems().clear();  

          for (int i=0; i<100; i++) {                
             Platform.runLater(new Runnable() {
                 @Override public void run() {
                     group.getItems.add(i);
                 }
             });
         }
         return null;
     }
 };

It should happens when you try to change some component UI, like a label text. Running like that works always:

@FXML Label myLabel;

Platform.runLater(new Runnable(){
   myLabel.setText("some text");
});