0

When I use mEditor.putString in the background service, it occur this:

Thread Name: 'pool-2-thread-1'

Back traces starts:

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)

Back traces ends.

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);
    }

}
nicky lin
  • 59
  • 5
  • no,it is not same, cause this problem occur focus in android 4.2.2 ,it is very strange – nicky lin May 03 '16 at 12:53
  • 2
    Please add the code that caused this Exception. – petey May 03 '16 at 13:02
  • Looks like in your `SharedPreferencesUtil` the array is initialised with a fixed size and you are trying to add more elements than the max size. Add the code for `SharedPreferencesUtil`, specially the code where you initialise your array – dazito May 03 '16 at 14:36
  • public static void init(Context context) { mContext = context.getApplicationContext(); } mSharedPreferences = context.getSharedPreferences(fileName, Context.MODE_PRIVATE); this is android system code,i didt init the fixed size of it. :http://developer.android.com/intl/zh-cn/reference/android/content/SharedPreferences.Editor.html – nicky lin May 04 '16 at 02:34

0 Answers0