I created a program to read a serial port, plot the data, and show the value. I am using a SwingWorker to collect, check, and plot the values while allowing the user to stop the data collection within the GUI. I believe I am receiving the modification exception when I try to plot the value as well as show the exact value.
Below is a simplified version of the doInBackground(). The lines I erased are essentially checking and comparing of the value read.
protected Integer doInBackground()
while (true && !isCancelled()) {
value = initandReadCOM();
// I also check and compare the value
publish(value);
}
return 0;
}
I am then using the process
command to plot the data. The closest thread on this problem that I could find suggested using this.
@Override
protected void process(List<Float> chunks) {
super.process(chunks);
float factor = chunks.get(chunks.size() - 1);
seriesUpdated = getSeries();
SetDataField(factor);
this.seriesUpdated.add(new Millisecond(), factor);
}
The SetDataField
and seriesUpdated
method are listed below if they are needed to help diagnose the problem.
public void SetDataField(float n) {
this.data_.setText("Data: " + String.valueOf(n));
}
public TimeSeries getSeries() {
return this.series;
}
As the program runs a for longer period of time this exception begins to show itself more often. Any and all help would be greatly appreciated.
Also, please let me know if you need to see anything else to help. Thanks
EDIT: Below is the stacktrace
Exception in thread "AWT-EventQueue-0" java.util.ConcurrentModificationException
at java.util.ArrayList$Itr.checkForComodification(Unknown Source)
at java.util.ArrayList$Itr.next(Unknown Source)
at java.util.Collections$UnmodifiableCollection$1.next(Unknown Source)
at org.jfree.chart.plot.XYPlot.drawRangeMarkers(XYPlot.java:4088)
at org.jfree.chart.plot.XYPlot.draw(XYPlot.java:3281)
at org.jfree.chart.JFreeChart.draw(JFreeChart.java:1226)
at org.jfree.chart.ChartPanel.paintComponent(ChartPanel.java:1612)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JComponent.paintToOffscreen(Unknown Source)
at javax.swing.RepaintManager$PaintManager.paintDoubleBuffered(Unknown Source)
at javax.swing.RepaintManager$PaintManager.paint(Unknown Source)
at javax.swing.RepaintManager.paint(Unknown Source)
at javax.swing.JComponent._paintImmediately(Unknown Source)
at javax.swing.JComponent.paintImmediately(Unknown Source)
at javax.swing.RepaintManager$3.run(Unknown Source)
at javax.swing.RepaintManager$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
at javax.swing.RepaintManager.prePaintDirtyRegions(Unknown Source)
at javax.swing.RepaintManager.access$1000(Unknown Source)
at javax.swing.RepaintManager$ProcessingRunnable.run(Unknown Source)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$200(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)