2

将字符串提交到 SharedPreferences 时出现以下异常。异常是任意的,不会一直发生。有没有人遇到过这个问题?

这是我的代码:

mSettings = PreferenceManager.getDefaultSharedPreferences(ctx);
long id= 358375;
SharedPreferences.Editor e = mSettings.edit();
e.putLong("some_key", id);
e.commit();

这是一个例外:

08-20 10:35:27.175: W/SharedPreferencesImpl(648): writeToFile: Got exception:
08-20 10:35:27.175: W/SharedPreferencesImpl(648): java.io.IOException: java.nio.charset.CoderResult[Malformed-input error with erroneous input length 1]
08-20 10:35:27.175: W/SharedPreferencesImpl(648):   at com.android.internal.util.FastXmlSerializer.flush(FastXmlSerializer.java:225)
08-20 10:35:27.175: W/SharedPreferencesImpl(648):   at com.android.internal.util.FastXmlSerializer.endDocument(FastXmlSerializer.java:183)
08-20 10:35:27.175: W/SharedPreferencesImpl(648):   at com.android.internal.util.XmlUtils.writeMapXml(XmlUtils.java:186)
08-20 10:35:27.175: W/SharedPreferencesImpl(648):   at android.app.SharedPreferencesImpl.writeToFile(SharedPreferencesImpl.java:576)
08-20 10:35:27.175: W/SharedPreferencesImpl(648):   at android.app.SharedPreferencesImpl.access$800(SharedPreferencesImpl.java:48)
08-20 10:35:27.175: W/SharedPreferencesImpl(648):   at android.app.SharedPreferencesImpl$2.run(SharedPreferencesImpl.java:491)
08-20 10:35:27.175: W/SharedPreferencesImpl(648):   at android.app.SharedPreferencesImpl.enqueueDiskWrite(SharedPreferencesImpl.java:512)
08-20 10:35:27.175: W/SharedPreferencesImpl(648):   at android.app.SharedPreferencesImpl.access$100(SharedPreferencesImpl.java:48)
08-20 10:35:27.175: W/SharedPreferencesImpl(648):   at android.app.SharedPreferencesImpl$EditorImpl.commit(SharedPreferencesImpl.java:434)
4

0 回答 0