[英]JavaFx2: Nullpointer in AbstractTimer
Im getting the following NullpointerException
, when i update a lot of JavaFX-charts: 当我更新许多JavaFX图表时,我收到以下NullpointerException
:
java.lang.NullPointerException
at com.sun.scenario.animation.AbstractMasterTimer.timePulseImpl(AbstractMasterTimer.java:366)
at com.sun.scenario.animation.AbstractMasterTimer$MainLoop.run(AbstractMasterTimer.java:289)
at com.sun.javafx.tk.quantum.QuantumToolkit.pulse(QuantumToolkit.java:459)
at com.sun.javafx.tk.quantum.QuantumToolkit$9.run(QuantumToolkit.java:332)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.access$100(WinApplication.java:17)
at com.sun.glass.ui.win.WinApplication$3$1.run(WinApplication.java:67)
at java.lang.Thread.run(Thread.java:744)
and the JavaFX-Thread is going to crash completeley. JavaFX-Thread将崩溃。
Im using JavaFX from a Swing based Application to show around 20 charts, who are updatet with new data every 10 seconds. 我使用基于Swing的应用程序中的JavaFX来显示大约20个图表,这些图表每10秒更新一次。 2 of them are updatet every 2 seconds. 每2秒更新2个。 Every update is running in a Platform.runLater(). 每个更新都在Platform.runLater()中运行。 So 20 runLaters every 10 seconds. 因此,每10秒运行20次。 I have read, that the JavaFX-Thread or EventQueue will be swamped with too many runLater's. 我读过,JavaFX-Thread或EventQueue将被太多的runLater淹没。 So i reduced the calls of PLatform.runLater to 3 every 10 seconds and everything was running fine.But then i had to redo the 20 calls again, because we can't use Java 1.7 from the side, where i could gather all updates in 3 runLater. 所以我每10秒将PLatform.runLater的调用减少到3次,一切运行良好。但是随后我不得不再次重做20次调用,因为我们不能从侧面使用Java 1.7,因为我可以在其中收集所有更新3 runLater。 Now we are getting the Nullpointer again. 现在,我们再次获得了Nullpointer。 Is the Nullpointer caused by overloading the JavaFX-Thread? Nullpointer是由JavaFX-Thread重载引起的吗? Or do i have another Problem here? 还是我在这里还有其他问题?
Here is a example for a update method that is running in a Platform.runlater: 这是在Platform.runlater中运行的更新方法的示例:
public static void updateBarChart(final ObservableList<XYChart.Series<String, Number>> oldData, final Map<String, Number> newData) {
Platform.runLater(new Runnable() {
@Override
public void run() {
logger.trace("ChartUpdater.updateBarChart");
Series<String, Number> series = oldData.get(0);
ObservableList<Data<String, Number>> listData = series.getData();
Set<String> keySet = newData.keySet();
outer: for (String string : keySet) {
boolean exists = false;
for (Data<String, Number> data : listData) {
if (data.getXValue().equals(string)) {
data.setYValue(newData.get(string));
Tooltip.install(data.getNode(), new Tooltip(data.getYValue().toString()));
exists = true;
continue outer;
}
}
if (!exists) {
final Data<String, Number> data = new BarChart.Data<String, Number>(string, newData.get(string));
series.getData().add(data);
displayLabelForData(data);
}
}
double scale = 1.0;
if (series.getData().size() == 2) {
scale = 0.5d;
}
else if (series.getData().size() == 1) {
scale = 0.2d;
}
if (scale != 1.0d) {
for (Data<String, Number> dataObeject : series.getData()) {
dataObeject.getNode().setScaleX(scale);
}
}
}
});
}
How about updating your JavaFX? 如何更新JavaFX? I'm not sure for which versions but AbstractMasterTimer and a lot of other sources have already changed. 我不确定哪个版本,但是AbstractMasterTimer和许多其他来源已经更改。
I identified the source of the problem. 我确定了问题的根源。 Beside the charts i used third party Gauges. 在图表旁边,我使用了第三方仪表。 These were causing the Nullpointer. 这些导致空指针。 So i kicked them, and everything is running fine now. 所以我踢了他们,一切现在都运行良好。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.