Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8114423

LineChart: Resetting the data inside a Linechart series results in a NullPointerException

    Details

      Description

      I have a multiple Linechart data series added to a line chart as defined under

      public static ObservableList<LineChart.Series> dataSeries = FXCollections.
                  observableArrayList(
                  new LineChart.Series("Take-Off Limit A", FXCollections.
                  observableArrayList()),
                  new LineChart.Series("Take-off Limit B", FXCollections.
                  observableArrayList()),
                  new LineChart.Series("Zero Fuel Limit", FXCollections.
                  observableArrayList()),
                  new LineChart.Series("", FXCollections.observableArrayList()));

      However, I want that the last series added in the above list of series to have data containing value of just one single point, I want to refresh this point when user performs certain action

      so In my action handler I am doing

      dataSeries.get(3).getData().
                      set( 0, new LineChart.Data(Double.valueOf(cg), Double.valueOf(
                      weight)));

      which throws a NullPointerException

      Here is the stacktrace

      java.lang.NullPointerException
      at javafx.scene.chart.LineChart.dataItemRemoved(LineChart.java:168)
      at javafx.scene.chart.XYChart.dataItemsChanged(XYChart.java:306)
      at javafx.scene.chart.XYChart.access$2500(XYChart.java:35)
      at javafx.scene.chart.XYChart$Series$1.onChanged(XYChart.java:1111)
      at com.sun.javafx.collections.ObservableListWrapper.callObservers(ObservableListWrapper.java:62)
      at com.sun.javafx.collections.ObservableListWrapper.set(ObservableListWrapper.java:196)
      at envelopetest.EnvelopeTest.resetCGData(EnvelopeTest.java:52)
      at envelopetest.EnvelopeTest$1.handle(EnvelopeTest.java:36)
      at envelopetest.EnvelopeTest$1.handle(EnvelopeTest.java:33)
      at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:59)
      at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:161)
      at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:114)
      at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:37)
      at javafx.scene.Node$19.dispatchEvent(Node.java:5409)
      at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:92)
      at javafx.event.Event.fireEventImpl(Event.java:185)
      at javafx.event.Event.fireEvent(Event.java:170)
      at javafx.scene.Node.fireEvent(Node.java:5514)
      at javafx.scene.control.Button.fire(Button.java:138)
      at com.sun.javafx.scene.control.behavior.ButtonBehavior.mouseReleased(ButtonBehavior.java:164)
      at com.sun.javafx.scene.control.skin.SkinBase$4.handle(SkinBase.java:269)
      at com.sun.javafx.scene.control.skin.SkinBase$4.handle(SkinBase.java:262)
      at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:55)
      at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:161)
      at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:114)
      at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:37)
      at javafx.scene.Node$19.dispatchEvent(Node.java:5409)
      at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:92)
      at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:35)
      at javafx.scene.Node$19.dispatchEvent(Node.java:5409)
      at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:92)
      at javafx.event.Event.fireEventImpl(Event.java:185)
      at javafx.event.Event.fireEvent(Event.java:175)
      at javafx.scene.Node.fireEvent(Node.java:5514)
      at javafx.scene.Scene$MouseHandler.process(Scene.java:2087)
      at javafx.scene.Scene$MouseHandler.process(Scene.java:1934)
      at javafx.scene.Scene$MouseHandler.access$1000(Scene.java:1906)
      at javafx.scene.Scene.impl_processMouseEvent(Scene.java:1007)
      at javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:1553)
      at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:122)
      at com.sun.glass.ui.View.handleMouseEvent(View.java:254)
      at com.sun.glass.ui.View.notifyMouse(View.java:511)
      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.run(WinApplication.java:51)
      at java.lang.Thread.run(Thread.java:619)

      If I call add instead of set the same thing works fine,

      dataSeries.get(3).getData().
                      add( Envelope.dataSeries.get(3).getData().size(), new LineChart.Data(Double.valueOf(cg), Double.valueOf(
                      weight)));

       but it plots a line between the current position of the point to the newly added point which I dont want, I tried clearing the list and adding the the point again like this

      dataSeries.get(3).getData().clear();

      dataSeries.get(3).getData().
                      add( Envelope.dataSeries.get(3).getData().size(), new LineChart.Data(Double.valueOf(cg), Double.valueOf(
                      weight)));

      but still it draws a line for some reasons

      I have attached a small project demonstrating the same

      Execute the EnvelopeTest.java from the attached project

      Click on Reset button to change the value of the point added in the last data series as shown above. One can observe that a NullpointerException is thrown.

      Now comment the line no 36 and uncomment the line no 37 of the EnvelopeTest.java and re-execute it . This will add the newly calculated point to the same data series without throwing any exception, which shows up as a line.

        Attachments

          Activity

            People

            • Assignee:
              psomashe Parvathi Somashekar (Inactive)
              Reporter:
              abhilshitjfx Abhilshit (Inactive)
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Due:
                Created:
                Updated:
                Resolved:
                Imported: