我创建了一个程序来读取串行端口、绘制数据并显示值。我正在使用 SwingWorker 来收集、检查和绘制值,同时允许用户在 GUI 中停止数据收集。当我尝试绘制值并显示确切值时,我相信我收到了修改异常。
下面是 doInBackground() 的简化版本。我擦除的行本质上是检查和比较读取的值。
protected Integer doInBackground()
while (true && !isCancelled()) {
value = initandReadCOM();
// I also check and compare the value
publish(value);
}
return 0;
}
然后我使用process
命令来绘制数据。我能找到的关于这个问题的最接近的线程建议使用这个。
@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);
}
如果需要帮助诊断问题,下面列出了SetDataField
and方法。seriesUpdated
public void SetDataField(float n) {
this.data_.setText("Data: " + String.valueOf(n));
}
public TimeSeries getSeries() {
return this.series;
}
随着程序运行时间的延长,此异常开始更频繁地出现。任何和所有的帮助将不胜感激。
另外,如果您需要其他帮助,请告诉我。谢谢
编辑:下面是堆栈跟踪
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)