Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/357.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
为什么我会得到java.lang.IllegalStateException“;不在FX应用程序线程上“;关于JavaFX?_Java_Javafx 2_Smack - Fatal编程技术网

为什么我会得到java.lang.IllegalStateException“;不在FX应用程序线程上“;关于JavaFX?

为什么我会得到java.lang.IllegalStateException“;不在FX应用程序线程上“;关于JavaFX?,java,javafx-2,smack,Java,Javafx 2,Smack,我有一个应用程序,它有一个TableView,它有一个附加的监听器,所以它在检测到更改时会立即刷新,但问题是我得到的java.lang.IllegalStateException:不是在FX应用程序线程上;currentThread=Smack侦听器处理器(0)。 这是我的密码: /** * This function resets the pagination pagecount */ public void resetPage() { try { System.o

我有一个应用程序,它有一个
TableView
,它有一个附加的监听器,所以它在检测到更改时会立即刷新,但问题是我得到的
java.lang.IllegalStateException:不是在FX应用程序线程上;currentThread=Smack侦听器处理器(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");
                    }
                }
            }
         });
}
/**
*此函数用于重置分页分页计数
*/
公共页面(第页){
试一试{
系统输出打印项次(“重置”);
int tamloster=this.loginManager.getRosterService().getRosterList().size();
paginationContactos.setPageCount((int)(Math.ceil(tamloster*1.0/limit.get());
int tamEnviados=this.loginManager.getRosterService().getEnviadasList().size();
paginationneviadas.setPageCount((int)(Math.ceil(tamEnviados*1.0/limit.get());
int tamricibidas=this.loginManager.getRosterService().getRecibidasList().size();
paginationRecibidas.setPageCount((int)(Math.ceil(tamRecibidas*1.0/limit.get());
}捕获(例外e){
e、 printStackTrace();
}
}
公共无效剂量测定法(){
this.loginManager.getRosterService().getRosterList().addListener(新ListChangeListener()){
@凌驾
更改公众假期(

javafx.collections.ListChangeListener.Changejavafx代码允许从javafx应用程序线程更新UI。但是从上面的异常消息可以看出,它没有使用FX应用程序线程


您可以修复的一种方法是从resetPage方法启动FX应用程序线程并在那里进行修改。

用户界面不能从非应用程序线程直接更新。相反,请使用
Platform.runLater()
,将逻辑放在可运行对象内。例如:

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.
  }
);

我有一个类似的问题,我在没有使用
平台的情况下修复了。runLater()

“java.lang.IllegalStateException:不在FX应用程序线程上;currentThread=thread-6”


你能详细说明一下我如何启动一个FX应用程序线程吗?你把这个代码放在哪里?我试着在实例化我的Stage并设置Stage时这样做,但是我没有得到错误,但是页面返回为空白。
Button play = new Button("Play");
EventHandler<ActionEvent> playHandler = e1 -> {
    Runnable runnable = () -> {

        play.setText("Pause");

        EventHandler<ActionEvent> timelineHandler e2 -> play();
        timeline = new Timeline(new KeyFrame(Duration.millis(2000), timelineHandler));
        timeline.setCycleCount(Timeline.INDEFINITE);
        timeline.play();

    };
    Thread t = new Thread(runnable);
    t.start();
};
play.setOnAction(playHandler);
Button play = new Button("Play");
EventHandler<ActionEvent> playHandler = e1 -> {
    play.setText("Pause");
    Runnable runnable = () -> {

        EventHandler<ActionEvent> timelineHandler e2 -> play();
        timeline = new Timeline(new KeyFrame(Duration.millis(2000), timelineHandler));
        timeline.setCycleCount(Timeline.INDEFINITE);
        timeline.play();

    };
    Thread t = new Thread(runnable);
    t.start();
};
play.setOnAction(playHandler);