我用android.support.v4.util.ArrayMap
安卓ArrayMap拋出java.lang.ClassCastException:java.lang.String中不能被強制轉換爲java.lang.Object繼承[]
這樣
ArrayMap<String, ArrayList<Object>> group = new ArrayMap<>();
,但我打電話ArrayMap.put(key,value)
在allocArrays(final int size)
方法中拋出ClassCastException
。在這條線
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];
非常感謝!
拋出java.lang.ClassCastException:java.lang.String中不能被強制轉換爲java.lang.Object繼承[] – yangll
你的代碼是如此messedup花花公子。 – user6657161
mBaseCache是一個對象還是一個對象數組? –