I using a JavaFX LineChart in my Swing application and when try to clear the series data i get this exception.
My code just call the clear method, the call is made in the JavaFX thread using Platform.runLater, i using 1.7.0_09 on ubuntu, is there any problems with my code or is this a bug in JavaFX.
series.getData().clear();
series is an XYChart.Series object
Exception in runnable
java.lang.NullPointerException
at javafx.scene.chart.LineChart.dataItemRemoved(LineChart.java:275)
at javafx.scene.chart.XYChart.dataItemsChanged(XYChart.java:470)
at javafx.scene.chart.XYChart.access$2500(XYChart.java:72)
at javafx.scene.chart.XYChart$Series$1.onChanged(XYChart.java:1462)
at com.sun.javafx.collections.ListListenerHelper$SingleChange.fireValueChangedEvent(ListListenerHelper.java:134)
at com.sun.javafx.collections.ListListenerHelper.fireValueChangedEvent(ListListenerHelper.java:48)
at com.sun.javafx.collections.ObservableListWrapper.callObservers(ObservableListWrapper.java:97)
at com.sun.javafx.collections.ObservableListWrapper.clear(ObservableListWrapper.java:184)
The problem is now solved, it seems it is a bug of JavaFX.
I have solved by adding
lineChart.setAnimated(false);
and it all works fine. In JIRA Kenai it has been proposed as bug by commenting lineChart.setCreateSymbols(false);
This also works but I think it is not the right answer, I can use .setCreateSymbols(false)
or (true)
having setted setAnimated(false);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With