java.util.ConcurrentModificationException和SharedPreference [英] java.util.ConcurrentModificationException and SharedPreference

查看:92
本文介绍了java.util.ConcurrentModificationException和SharedPreference的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在崩溃日志中发现了此崩溃.我不知道什么时候发生.有人可以给我建议是什么原因?也许有人崩溃了.

I've found this crash in crash logs. I don't know when it is happening. Can someone give me advice what is the reason? Maybe someone has same crash.

java.util.ConcurrentModificationException
       at java.util.HashMap$HashIterator.nextEntry(HashMap.java:787)
       at java.util.HashMap$KeyIterator.next(HashMap.java:814)
       at com.android.internal.util.XmlUtils.writeSetXml(XmlUtils.java:350)
       at com.android.internal.util.XmlUtils.writeValueXml(XmlUtils.java:688)
       at com.android.internal.util.XmlUtils.writeMapXml(XmlUtils.java:295)
       at com.android.internal.util.XmlUtils.writeMapXml(XmlUtils.java:264)
       at com.android.internal.util.XmlUtils.writeMapXml(XmlUtils.java:230)
       at com.android.internal.util.XmlUtils.writeMapXml(XmlUtils.java:187)
       at android.app.SharedPreferencesImpl.writeToFile(SharedPreferencesImpl.java:597)
       at android.app.SharedPreferencesImpl.access$800(SharedPreferencesImpl.java:51)
       at android.app.SharedPreferencesImpl$2.run(SharedPreferencesImpl.java:512)
       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
       at java.lang.Thread.run(Thread.java:818)

推荐答案

在使用SharedPreferences getStringSet 方法时,我们已经看到了此异常.此方法返回一个不应修改的集合.在将SharedPreferences对象序列化为flash时修改此集合将产生ConcurrentModificationException.

We had seen this exception when using the SharedPreferences getStringSet method. This method returns a set that should not be modified. Modifying this set while the SharedPreferences object is being serialized to flash will produce a ConcurrentModificationException.

如果您使用 getAll 并修改返回的地图,也会发生这种情况.

This will also happen if you use getAll and modify the returned map.

请参见文档

这篇关于java.util.ConcurrentModificationException和SharedPreference的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆