访问共享首选项时,Android中的ConcurrentModificationException [英] ConcurrentModificationException in Android while accessing Shared Preferences

查看:150
本文介绍了访问共享首选项时,Android中的ConcurrentModificationException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我开发一个Android应用程序,我遇到了异常,我没有任何线索;我有google的相关主题,但没有一个帮助。

When I develop an android app, I run into the exception which I do not have any clue; I have googled related topics but none of them helped.

Fatal Exception: java.util.ConcurrentModificationException
    java.util.HashMap$HashIterator.nextEntry (HashMap.java:806)
    java.util.HashMap$KeyIterator.next (HashMap.java:833)
    com.android.internal.util.XmlUtils.writeSetXml (XmlUtils.java:298)
    com.android.internal.util.XmlUtils.writeValueXml (XmlUtils.java:447)
    com.android.internal.util.XmlUtils.writeMapXml (XmlUtils.java:241)
    com.android.internal.util.XmlUtils.writeMapXml (XmlUtils.java:181)
    android.app.SharedPreferencesImpl.writeToFile (SharedPreferencesImpl.java:596)
    android.app.SharedPreferencesImpl.access$800 (SharedPreferencesImpl.java:52)
    android.app.SharedPreferencesImpl$2.run (SharedPreferencesImpl.java:511)
    java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1112)
    java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:587) 
    java.lang.Thread.run (Thread.java:841)


推荐答案

请确保您没有从任何类型的后台线程访问首选项。此外,所有添加到偏好设置的方法必须同步(如果您有自己的偏好管理类)

Please ensure that you are not accessing the preferences from any type of background thread. Also all your methods to add to preference must be synchronised(if you have your own preference managing class)

这篇关于访问共享首选项时,Android中的ConcurrentModificationException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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