I am using a library that sometimes (about 1 of 100 times) throws a ConcurrentModificationException
leading to an app crash.
The stacktrace does not mention any code of mine but instead the code of the library. I tried to catch the exception where I call the library however it does not work.
I guess the exception is thrown in a new thread within the library.
How could I catch such an exception?
Libary: Old Philips Hue Java library. (I am going to switch to the new one, soon.)
Exception:
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)
I guess you modify array value while you iterating throu it.
Java Collection classes are fail-fast, which means if the Collection will be changed while some thread is traversing over it using iterator, the iterator.next() will throw ConcurrentModificationException.
Here is how to avoid it : How to avoid java.util.ConcurrentModificationException when iterating through and removing elements from an ArrayList
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.