ConcurrentModificationException-如何解决?

时间:2018-12-09 10:44:50

标签: android android-fragments android-lifecycle

有一个包含激活容器的应用程序,其中替换了2个片段(列表和详细信息)。我每1000个用户中有0.5个用户收到“ RuntimeException原因:ConcurrentModificationException”。我自己无法捕获它。我用的是moxy,dagger,rx。

我知道在迭代期间修改集合时会发生此异常。但是我不这样做。

java.lang.RuntimeException: 
  at android.app.ActivityThread.performPauseActivityIfNeeded (ActivityThread.java:4179)
  at android.app.ActivityThread.performPauseActivity (ActivityThread.java:4145)
  at android.app.ActivityThread.performPauseActivity (ActivityThread.java:4119)
  at android.app.ActivityThread.handlePauseActivity (ActivityThread.java:4093)
  at android.app.ActivityThread.-wrap18 (ActivityThread.java)
  at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1654)
  at android.os.Handler.dispatchMessage (Handler.java:102)
  at android.os.Looper.loop (Looper.java:154)
  at android.app.ActivityThread.main (ActivityThread.java:6776)
  at java.lang.reflect.Method.invoke (Method.java)
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:1518)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1408)
Caused by: java.util.ConcurrentModificationException: 
  at i.put (i.java:101)
  at fo.a (fo.java:44)
  at fm.onActivityPaused (fm.java:53)
  at android.app.Application.dispatchActivityPaused (Application.java:249)
  at android.app.Activity.onPause (Activity.java:1678)
  at android.support.v4.app.FragmentActivity.onPause (FragmentActivity.java)
  at android.app.Activity.performPause (Activity.java:7158)
  at android.app.Instrumentation.callActivityOnPause (Instrumentation.java:1330)
  at android.app.ActivityThread.performPauseActivityIfNeeded (ActivityThread.java:4168)
  at android.app.ActivityThread.performPauseActivity (ActivityThread.java:4145)
  at android.app.ActivityThread.performPauseActivity (ActivityThread.java:4119)
  at android.app.ActivityThread.handlePauseActivity (ActivityThread.java:4093)
  at android.app.ActivityThread.-wrap18 (ActivityThread.java)
  at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1654)
  at android.os.Handler.dispatchMessage (Handler.java:102)
  at android.os.Looper.loop (Looper.java:154)
  at android.app.ActivityThread.main (ActivityThread.java:6776)
  at java.lang.reflect.Method.invoke (Method.java)
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:1518)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1408)

我认为是由于以下原因造成的:

  at i.put (i.java:101)
  at fo.a (fo.java:44)
  at fm.onActivityPaused (fm.java:53)

1 个答案:

答案 0 :(得分:0)

您正在为每个循环使用,但同时您不能修改list。用于基于(int i)的循环。