java.util.ConcurrentModificationException

java.util.ConcurrentModificationException
at java.util.AbstractList I t r . c h e c k F o r C o m o d i f i c a t i o n ( U n k n o w n S o u r c e ) a t j a v a . u t i l . A b s t r a c t L i s t Itr.checkForComodification(Unknown Source) at java.util.AbstractList Itr.checkForComodification(UnknownSource)atjava.util.AbstractListItr.next(Unknown Source)
at com.uaes.ucm.dialog.artifact.BCUpgradeResultDialog.shinkResult(BCUpgradeResultDialog.java:205)
at com.uaes.ucm.dialog.artifact.BCUpgradeResultDialog.createDialogArea(BCUpgradeResultDialog.java:115)
at org.eclipse.jface.dialogs.TitleAreaDialog.createContents(TitleAreaDialog.java:155)
at org.eclipse.jface.window.Window.create(Window.java:431)
at org.eclipse.jface.dialogs.Dialog.create(Dialog.java:1089)
at org.eclipse.jface.window.Window.open(Window.java:790)
at com.uaes.ucm.tableview.BCUpradeManagerView$AutoUpgrade.run(BCUpradeManagerView.java:698)
at org.eclipse.jface.action.Action.runWithEvent(Action.java:498)
at org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection(ActionContributionItem.java:584)
at org.eclipse.jface.action.ActionContributionItem.access$2(ActionContributionItem.java:501)
at org.eclipse.jface.action.ActionContributionItem$5.handleEvent(ActionContributionItem.java:411)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1053)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4165)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3754)
at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2696)
at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2660)
at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2494)
at org.eclipse.ui.internal.Workbench$7.run(Workbench.java:674)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:667)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
at com.uaes.ucm.application.Application.start(Application.java:157)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:344)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:622)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:577)
at org.eclipse.equinox.launcher.Main.run(Main.java:1410)
at org.eclipse.equinox.launcher.Main.main(Main.java:1386)

在对List使用remove方法时可能会出现以上异常(原因是使用此种方法时在for循环中,对于List中的某一个对象有两个对象指向同一个位置,一个是遍历用的元素,一个是迭代器,这样使用remove方法就可能会报错),对此本文给出了2种简单的解决方法:

//例子:(有向边,第一个字符串为起点,第二个为终点,整数为边的权值)Edge<String,String,Integer>,edges:List<Edge>,删除edges中以某个顶点为原点的有向边,顶点为字符串类型。
String source = "ABc";
//可能出现上述异常的方法
for(Edge e:edges){
    if(e.getSource() == source)
        edges.remove(e);
}
//解决方法一:在循环结束后再使用remove方法
int index = -1;
for(Edge e:edges){
    if(e.getSource() == source)
        index = edges.indexOf(e);//获取边e在List中的下标
}
edges.remove(edges.get(index))
//解决方法二:使用迭代器Iterator的remove方法
Iterator<String,String,Integer> it = edges.iterator();
while(it.hasNext()){
    Edge e = it.next();
    if(e.getSource() == source)
        it.remove();
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值