我使用android.support.v4.util.ArrayMap

像这样

ArrayMap<String, ArrayList<Object>> group = new ArrayMap<>();


但我叫ArrayMap.put(key,value)

ClassCastException方法中抛出allocArrays(final int size)

 private void allocArrays(final int size) {
    if (size == (BASE_SIZE*2)) {
        synchronized (ArrayMap.class) {
            if (mTwiceBaseCache != null) {
                final Object[] array = mTwiceBaseCache;
                mArray = array;
                mTwiceBaseCache = (Object[])array[0];
                mHashes = (int[])array[1];
                array[0] = array[1] = null;
                mTwiceBaseCacheSize--;
                if (DEBUG) Log.d(TAG, "Retrieving 2x cache " + mHashes
                        + " now have " + mTwiceBaseCacheSize + " entries");
                return;
            }
        }
    } else if (size == BASE_SIZE) {
        synchronized (ArrayMap.class) {
            if (mBaseCache != null) {
                final Object[] array = mBaseCache;
                mArray = array;
                mBaseCache = (Object[])array[0];
                mHashes = (int[])array[1];
                array[0] = array[1] = null;
                mBaseCacheSize--;
                if (DEBUG) Log.d(TAG, "Retrieving 1x cache " + mHashes
                        + " now have " + mBaseCacheSize + " entries");
                return;
            }
        }
    }

    mHashes = new int[size];
    mArray = new Object[size<<1];
}


应用程序在此行mBaseCache = (Object[])array[0];崩溃

很感谢 !!!

最佳答案

问题的原因是多线程。

修复此错误https://issuetracker.google.com/issues/37114373
更新支持V25.4.0已修复

关于java - android ArrayMap引发java.lang.ClassCastException:无法将java.lang.String强制转换为java.lang.Object [],我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/39343332/

10-09 02:09