为什么我在JavaFX上得到java.lang.IllegalStateException“不在FX应用程序线程上”?我有一个TableView具有附加侦听器的应用程序,因此一旦检测到更改就会刷新,但问题是我得到了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");
}
}
}
});}它进入resetPage方法,我得到了那个异常。为什么会这样?我该如何解决?提前致谢。
2 回答

有只小跳蛙
TA贡献1824条经验 获得超8个赞
无法从非应用程序线程直接更新用户界面。相反,使用Platform.runLater()
Runnable对象中的逻辑。例如:
Platform.runLater(new Runnable() { @Override public void run() { // Update UI here. }});
作为lambda表达式:
// Avoid throwing IllegalStateException by running from a non-JavaFX thread.Platform.runLater( () -> { // Update UI here. });
添加回答
举报
0/150
提交
取消