0

I get the following error :

Exception in thread "Thread-5" java.lang.IllegalStateException: Not on FX application thread; currentThread = Thread-5"

When this statement is executed :

 root.getChildren().add(carros); 

The relevant code snippet is :

public void createCar(String origem, String destino){  
        Group carros = new Group();  
        carro1 = new Rectangle(30,15,Color.DARKMAGENTA);  
        carros.getChildren().add(carro1);  
        root.getChildren().add(carros);  
        animate(carros, (origem+"->"+destino) );   
 }    
c0der
  • 18,467
  • 6
  • 33
  • 65

1 Answers1

1

You are trying the change JavaFX elements in a thread different from the FX application thread. You can use

Platform.runLater(new Runnable(){
// place the code here, that you want to execute
});

to run code that modifies JavaFX elements. See here for other answers to this question How to avoid Not on FX application thread; currentThread = JavaFX Application Thread error?

Community
  • 1
  • 1
Guenther
  • 2,035
  • 2
  • 15
  • 20