计时器错误java.lang.IllegalStateException

前端之家收集整理的这篇文章主要介绍了计时器错误java.lang.IllegalStateException前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我试图在JRE 8中显示一个标签,说明所有内容都只有3秒,因为我无法在JRE 7中使用DatePicker而且我发现了这个错误. @H_502_2@Exception in thread "Timer-2" java.lang.IllegalStateException: Not on FX application thread; currentThread = Timer-2 at com.sun.javafx.tk.Toolkit.checkFxUserThread(Unknown Source) at com.sun.javafx.tk.quantum.QuantumToolkit.checkFxUserThread(Unknown Source) at javafx.scene.Scene.addToDirtyList(Unknown Source) at javafx.scene.Node.addToSceneDirtyList(Unknown Source) at javafx.scene.Node.impl_markDirty(Unknown Source) at javafx.scene.Node$7.invalidated(Unknown Source) at javafx.beans.property.BooleanPropertyBase.markInvalid(Unknown Source) at javafx.beans.property.BooleanPropertyBase.set(Unknown Source) at javafx.css.StyleableBooleanProperty.set(Unknown Source) at javafx.scene.Node.setVisible(Unknown Source) at Pantallas.PersonalContabilidad$1.run(PersonalContabilidad.java:221) at java.util.TimerThread.mainLoop(Unknown Source) at java.util.TimerThread.run(Unknown Source)

正确是一个标签,我显示3秒,它在correct.setVisible(false)失败;这是第221行

@H_502_2@correct.setVisible(true); timer.schedule(new TimerTask() { @Override public void run() { correct.setVisible(false); } },3*1000);

解决方法

标签正确应该从FX应用程序线程更新.你应该在这里使用Platform.runLater(). @H_502_2@correct.setVisible(true); timer.schedule(new TimerTask() { @Override public void run() { Platform.runLater(new Runnable() { public void run() { correct.setVisible(false); } }); } },3*1000);
原文链接:https://www.f2er.com/java/128741.html

猜你在找的Java相关文章