I have a question on JavaFX. My program is working with a client-server model. The error occurs when calling a method over the server on the client (rmi-callback). I receive following error code when calling the method newGame
from the client program:
Exception in thread "JavaFX Application Thread" java.lang.IllegalStateException: Not on FX application thread; currentThread = RMI TCP Connection(1)-127.0.0.1
at com.sun.javafx.tk.Toolkit.checkFxUserThread(Toolkit.java:236)
at com.sun.javafx.tk.quantum.QuantumToolkit.checkFxUserThread(QuantumToolkit.java:423)
...
code of the client program:
public class LoginCLIENT extends Application implements Serializable {
@Override
public void start(Stage primaryStage) {
Registry registry;
try {
registry = LocateRegistry.getRegistry(4242);
server = (FPServerInterface)registry.lookup("ServerInterface");
} catch (RemoteException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (NotBoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
//not important code
}
public static void main(String[] args) {
launch(args);
}
public void newGame(SessionInterface Opponent) throws RemoteException{
alert = new Alert(AlertType.CONFIRMATION, "Yes or No");
Optional<ButtonType>result = alert.showAndWait();
if (result.isPresent() && result.get() == ButtonType.OK){
System.out.println("Lets play!!!");
}
}