為什么我在JavaFX上得到j(luò)ava.lang.IllegalStateException“不在FX應(yīng)用程序線程上”?我有一個(gè)TableView具有附加偵聽器的應(yīng)用程序,因此一旦檢測(cè)到更改就會(huì)刷新,但問題是我得到了java.lang.IllegalStateException: Not on FX application thread; currentThread = Smack Listener Processor (0)。這是我的代碼:/**
* This function resets the pagination pagecount
*/public void resetPage() {
try {
System.out.println("RESET");
int tamRoster = this.loginManager.getRosterService().getRosterList().size();
paginationContactos.setPageCount((int)(Math.ceil(tamRoster*1.0/limit.get())));
int tamEnviados = this.loginManager.getRosterService().getEnviadasList().size();
paginationEnviadas.setPageCount((int)(Math.ceil(tamEnviados*1.0/limit.get())));
int tamRecibidas = this.loginManager.getRosterService().getRecibidasList().size();
paginationRecibidas.setPageCount((int)(Math.ceil(tamRecibidas*1.0/limit.get())));
} catch (Exception e) {
e.printStackTrace();
}}public void doSomething () {
this.loginManager.getRosterService().getRosterList().addListener(new ListChangeListener<RosterDTO>() {
@Override
public void onChanged(
javafx.collections.ListChangeListener.Change<? extends RosterDTO> c) {
// TODO Auto-generated method stub
resetPage();
while (c.next()) {
if (c.wasPermutated()) {
System.out.println("PERM");
} else if (c.wasUpdated()) {
System.out.println("UPD");
} else {
System.out.println("ELSE");
}
}
}
});}它進(jìn)入resetPage方法,我得到了那個(gè)異常。為什么會(huì)這樣?我該如何解決?提前致謝。
2 回答

有只小跳蛙
TA貢獻(xiàn)1824條經(jīng)驗(yàn) 獲得超8個(gè)贊
無法從非應(yīng)用程序線程直接更新用戶界面。相反,使用Platform.runLater()
Runnable對(duì)象中的邏輯。例如:
Platform.runLater(new Runnable() { @Override public void run() { // Update UI here. }});
作為lambda表達(dá)式:
// Avoid throwing IllegalStateException by running from a non-JavaFX thread.Platform.runLater( () -> { // Update UI here. });
添加回答
舉報(bào)
0/150
提交
取消