2011-12-24 36 views
1

我被一个ConcurrentModificationException卡住了,我无法弄清楚在我的代码中发生了什么。所有这一切调试给我是这样的:当你正在修改的集合而遍历它发生如何找出ConcurrentModificationException崩溃的位置?

myApp [Android Application] 
DalvikVM[localhost:8631]  
    Thread [<1> main] (Suspended (exception ConcurrentModificationException)) 
     ViewRoot.draw(boolean) line: 1631 
     ViewRoot.performTraversals() line: 1329 
     ViewRoot.handleMessage(Message) line: 1944 
     ViewRoot(Handler).dispatchMessage(Message) line: 99 
     Looper.loop() line: 126 
     ActivityThread.main(String[]) line: 3997  
     Method.invokeNative(Object, Object[], Class, Class[], Class, int, boolean) line: not available [native method] 
     Method.invoke(Object, Object...) line: 491 
     ZygoteInit$MethodAndArgsCaller.run() line: 841 
     ZygoteInit.main(String[]) line: 599 
     NativeStart.main(String[]) line: not available [native method] 
    Thread [<8> Binder Thread #2] (Running) 
    Thread [<7> Binder Thread #1] (Running) 
    Thread [<9> AsyncTask #1] (Running) 
    Thread [<10> AsyncTask #2] (Running)  
    Daemon Thread [<12> [email protected]@40770068] (Running) 
    Thread [<11> AsyncTask #3] (Running)  
+0

您应该在logcat中获得完整的堆栈跟踪。在eclipse中使用'Window - > Show View - > Logcat'或从SDK文件夹启动'ddms'应用程序。崩溃后应该有一个带有标记* AndroidRuntime *的大红色块。 – 2011-12-24 12:26:27

+0

Logcat显示的唯一东西是isDEBUG/AndroidRuntime(899):>>>>>> AndroidRuntime START com.android.internal.os.RuntimeInit <<<<<<没有大分块... – michaelsmith

+0

哦,对不起,忘了说明了,在您错过了这种情况:当您处于调试模式时,您必须恢复执行,并且调试器停止在异常处。当您看到“强制关闭”对话框时,会打印日志语句。 – 2011-12-24 13:30:41

回答

0

ConcurrentModificationException。在这一点上,搜索一个foreach循环可能会更容易,因为您正在更改集合。

+0

我正在做的 map.getOverlays()。add(...); 在不同的地方。锁定/解锁会有帮助吗? – michaelsmith

+0

@michaelsmith:如果它在foreach里面,锁定不会帮助,因为你不是从不同的线程修改它。 – Tudor

+0

我其实是从不同的线程做的修改。所以锁定/解锁会很好? – michaelsmith