Page 1 of 1

IndexOutOfBoundsException

Posted: Fri Aug 15, 2003 11:05 pm
by DanM
Hi,

I am running a modified version of the MemoryUsage example from the Manual. It works fine for a while, but then it start printing the error below. It doesn't crash, it keeps running, and it only appears every 5 seconds ro so. I am not sure the graph is still accurate.
I am using JFreeChart 0.9.9.
Could you advise please?

Thanks.

Dan

java.lang.IndexOutOfBoundsException: Index: 577, Size: 577
at java.util.ArrayList.RangeCheck(ArrayList.java:508)
at java.util.ArrayList.get(ArrayList.java:320)
at org.jfree.data.time.TimeSeries.getDataPair(Unknown Source)
at org.jfree.data.time.TimeSeriesCollection.getXValue(Unknown Source)
at org.jfree.chart.renderer.StandardXYItemRenderer.drawItem(Unknown Sour
ce)
at org.jfree.chart.plot.XYPlot.render(Unknown Source)
at org.jfree.chart.plot.XYPlot.draw(Unknown Source)
at org.jfree.chart.JFreeChart.draw(Unknown Source)
at org.jfree.chart.ChartPanel.paintComponent(Unknown Source)
at javax.swing.JComponent.paint(JComponent.java:804)
at javax.swing.JComponent.paintWithOffscreenBuffer(JComponent.java:4735)

at javax.swing.JComponent.paintDoubleBuffered(JComponent.java:4688)
at javax.swing.JComponent._paintImmediately(JComponent.java:4632)
at javax.swing.JComponent.paintImmediately(JComponent.java:4464)
at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:404)

at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(System
EventQueueUtilities.java:117)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:178)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:443)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchTh
read.java:190)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThre
ad.java:144)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)

at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:130)

at java.awt.EventDispatchThread.run(EventDispatchThread.java:98)

Re: IndexOutOfBoundsException

Posted: Fri Jun 26, 2009 1:50 pm
by artipton
I am seeing the same thing... except that I am not running any modified versions.

Exception in thread "AWT-EventQueue-0" java.lang.IndexOutOfBoundsException: Index: 299, Size: 299
at java.util.ArrayList.RangeCheck(ArrayList.java:547)
at java.util.ArrayList.get(ArrayList.java:322)
at org.jfree.data.time.TimeSeries.getDataItem(TimeSeries.java:336)
at org.jfree.data.time.TimeSeriesCollection.getXValue(TimeSeriesCollection.java:422)
at org.jfree.chart.renderer.RendererUtilities.findLiveItemsUpperBound(RendererUtilities.java:170)
at org.jfree.chart.renderer.RendererUtilities.findLiveItems(RendererUtilities.java:243)
at org.jfree.chart.plot.XYPlot.render(XYPlot.java:3224)
at org.jfree.chart.plot.XYPlot.draw(XYPlot.java:2810)
at org.jfree.chart.JFreeChart.draw(JFreeChart.java:1222)
at org.jfree.chart.ChartPanel.paintComponent(ChartPanel.java:1354)
at javax.swing.JComponent.paint(JComponent.java:1022)
at javax.swing.JComponent.paintToOffscreen(JComponent.java:5104)
at javax.swing.RepaintManager$PaintManager.paintDoubleBuffered(RepaintManager.java:1382)
at javax.swing.RepaintManager$PaintManager.paint(RepaintManager.java:1313)
at javax.swing.BufferStrategyPaintManager.paint(BufferStrategyPaintManager.java:301)
at javax.swing.RepaintManager.paint(RepaintManager.java:1128)
at javax.swing.JComponent._paintImmediately(JComponent.java:5052)
at javax.swing.JComponent.paintImmediately(JComponent.java:4862)
at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:723)
at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:679)
at javax.swing.RepaintManager.seqPaintDirtyRegions(RepaintManager.java:659)
at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(SystemEventQueueUtilities.java:128)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)

Re: IndexOutOfBoundsException

Posted: Fri Jun 26, 2009 2:29 pm
by david.gilbert
I think this is a multi-threading problem that occurs when the dataset is updated in one thread while another thread (the AWT thread) is reading the dataset (while drawing the chart). The solution is to make sure the dataset update happens in the same thread as the chart drawing. If you change the actionPerformed() method to the following, I think the exception will not happen anymore:

Code: Select all

        public void actionPerformed(ActionEvent event) {
            Runnable updateData = new Runnable() {
                public void run() {
                    long f = Runtime.getRuntime().freeMemory();
                    long t = Runtime.getRuntime().totalMemory();
                    addTotalObservation(t);
                    addFreeObservation(f);
                }
            };
            SwingUtilities.invokeLater(updateData);
        }

Re: IndexOutOfBoundsException

Posted: Fri Jun 26, 2009 2:41 pm
by artipton
I currently do not have the 'actionPerformed' method implemented... and don't see where I can add an action listener to the chart. I am currently running jfreechart-1.0.9, is that why?

Re: IndexOutOfBoundsException

Posted: Fri Jun 26, 2009 2:46 pm
by david.gilbert
Oh, I assumed you were running the MemoryUsageDemo application, since you said you were seeing the same thing as the original poster.

Find the place where you update your dataset(s) and make sure that you only run that code from within the AWT event dispatch thread (so that it won't conflict with the chart repaint code).

Re: IndexOutOfBoundsException

Posted: Fri Jun 26, 2009 3:04 pm
by artipton
Ah, my bad... I apologize. Ok, I will implement the change. Thank you for your help.