我使用的库有时(大约100次中的1次)会抛出ConcurrentModificationException
,导致应用程序崩溃。
StackTrace没有提及我的任何代码,而是库的代码。我试图捕获我称之为库的例外,但是它不起作用。
我猜该例外是在库中的新线程中抛出的。
我怎么能发现这样的例外?
libary:旧飞利浦色调爪哇图书馆。(我将很快切换到新的。)
例外:
E/AndroidRuntime: FATAL EXCEPTION: Thread-21319
Process: my.package, PID: 21561
Theme: themes:{...}
java.util.ConcurrentModificationException
at java.util.ArrayList$ArrayListIterator.next(ArrayList.java:573)
at com.philips.lighting.hue.sdk.notification.impl.PHNotificationManagerImpl$3.onReceived(PHNotificationManagerImpl.java:180)
at com.philips.lighting.hue.sdk.notification.impl.PHHueResultReceiver.execute(PHHueResultReceiver.java:24)
at com.philips.lighting.hue.sdk.notification.impl.PHNotificationManagerImpl.notifyBridgeSearchResult(PHNotificationManagerImpl.java:188)
at com.philips.lighting.hue.sdk.upnp.PHBridgeSearchManagerImpl$1.run(PHBridgeSearchManagerImpl.java:198)
我想您在迭代时修改数组值。
Java收集课程是失败的,这意味着如果收集 当某些线程使用某些线程遍历它时将更改 迭代器,iterator.next()将投掷 concurrentModificationException。
这是避免它的方法:如何避免java.util.concurrentmodification exception迭代并从arraylist中删除元素