使用sharePref.putString时ArrayIndexOutOfBoundsException

时间:2016-05-03 12:51:02

标签: java android

当我在后台服务中使用mEditor.putString时,会出现这种情况:

主题名称:'pool-2-thread-1'

返回跟踪开始:

java.lang.ArrayIndexOutOfBoundsException: src.length=1 srcPos=0 dst.length=0 dstPos=881 length=1
at java.lang.System.arraycopy(Native Method)
at java.lang.String.getChars(String.java:889)
at com.android.internal.util.FastXmlSerializer.append(FastXmlSerializer.java:89)
at com.android.internal.util.FastXmlSerializer.append(FastXmlSerializer.java:113)
at com.android.internal.util.FastXmlSerializer.text(FastXmlSerializer.java:358)
at com.android.internal.util.XmlUtils.writeValueXml(XmlUtils.java:425)
at com.android.internal.util.XmlUtils.writeMapXml(XmlUtils.java:245)
at com.android.internal.util.XmlUtils.writeMapXml(XmlUtils.java:185)
at android.app.SharedPreferencesImpl.writeToFile(SharedPreferencesImpl.java:598)
at android.app.SharedPreferencesImpl.access$800(SharedPreferencesImpl.java:52)
at android.app.SharedPreferencesImpl$2.run(SharedPreferencesImpl.java:513)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
at java.lang.Thread.run(Thread.java:838)

后退痕迹结束。

SharedPreferencesUtil.putStringValue(mContext,
            ConstValueDef.BACKGROUNDPROCESS_SHAREDPREFERENCES_FILE_NAME,
            ConstValueDef.KEY_RECOMMEND_WIDGET_STRING_LOADING,
            mLoadingString);

public static void putStringValue(Context context, String fileName, String key, String value) {
    if (context == null) {
        return;
    }

    try {
        mSharedPreferences = context.getSharedPreferences(fileName, Context.MODE_PRIVATE);
        if (mSharedPreferences != null) {
            mEditor = mSharedPreferences.edit();
            if (mEditor != null) {
                mEditor.putString(key, value);
                mEditor.apply();
            }
        }
    } catch (Throwable e) {
        ExceptionHandler.processFatalException(e);
    }

}

0 个答案:

没有答案