I have an application with checkBox and 2 animated charts: Pie and Bar charts. When checkBox is checked, method which adds new data to a chart is fired. When checkBox is *un*checked, method which removes data from a chart is fired.
当我点击一个复选框不非常快时,一切都很好。但如果在动画完成之前再点击复选框,我就会重新发现这个错误:
java.lang.NullPointerException
at javafx.scene.chart.PieChart$7.handle(PieChart.java:370)
at javafx.scene.chart.PieChart$7.handle(PieChart.java:367)
at com.sun.scenario.animation.shared.TimelineClipCore.visitKeyFrame(TimelineClipCore.java:217)
at com.sun.scenario.animation.shared.TimelineClipCore.playTo(TimelineClipCore.java:158)
at javafx.animation.Timeline.impl_playTo(Timeline.java:182)
at com.sun.scenario.animation.shared.SingleLoopClipEnvelope.timePulse(SingleLoopClipEnvelope.java:119)
at javafx.animation.Animation.impl_timePulse(Animation.java:953)
at com.sun.scenario.animation.shared.AnimationPulseReceiver.timePulse(AnimationPulseReceiver.java:117)
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:454)
at com.sun.javafx.tk.quantum.QuantumToolkit$8.run(QuantumToolkit.java:325)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.access$100(WinApplication.java:29)
at com.sun.glass.ui.win.WinApplication$2$1.run(WinApplication.java:62)
at java.lang.Thread.run(Unknown Source)
这一切都只发生在PieChart。BarChart正常工作。
以下是在动作事件上检查框的方法 :
public void OnCheckFired(ActionEvent event) {
Boolean b = checkBox.isSelected();
chart.modifyChart(currentChart,b);
}
Thant是用来修改馅饼图表的代码:
@Override
public void makeModifications(Chart chart, Boolean b) {
PieChart pie = (PieChart) chart;
ObservableList<PieChart.Data> pieChartData = pie.getData();
pieChartData = modify(b, pieChartData);
pie.setData(pieChartData);
}
private ObservableList<Data> modify(Boolean b, ObservableList<PieChart.Data> pieChartData) {
if (b) {
pieChartData.add(new PieChart.Data("newValue", 34));
} else {
int size = pieChartData.size() - 1;
pieChartData.remove(size);
}
return pieChartData;
}