linker85 linker85 - 1 year ago 67
Java Question

why am I getting java.lang.IllegalStateException on javafx?

I have an application that has a

that has an attached listener so it refreshes as soon as it detects a change, but the thing is that I´m getting
java.lang.IllegalStateException: Not on FX application thread; currentThread = Smack Listener Processor (0)
Here is my code:

* This function resets the pagination pagecount
public void resetPage() {
try {
int tamRoster = this.loginManager.getRosterService().getRosterList().size();
int tamEnviados = this.loginManager.getRosterService().getEnviadasList().size();
int tamRecibidas = this.loginManager.getRosterService().getRecibidasList().size();
} catch (Exception e) {

public void doSomething () {
this.loginManager.getRosterService().getRosterList().addListener(new ListChangeListener<RosterDTO>() {
public void onChanged(
javafx.collections.ListChangeListener.Change<? extends RosterDTO> c) {
// TODO Auto-generated method stub
while ( {
if (c.wasPermutated()) {
} else if (c.wasUpdated()) {
} else {

Altough it enters the resetPage method, I get that exception.
Why is this happening?
How can I fix it?
Thanks in advance.

Answer Source

Indeed, MohamedSanaulla is right you can't update the UI from a thread that is not the application thread. But still, if you really want to modify your UI from a different thread use the Platform.runlater(new Runnable()) method. And put your modifications inside the Runnable object.

Example :

Platform.runLater(new Runnable() {
    public void run() {
        //if you change the UI, do it here !
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download