我無法加載gridview上的圖像,它總是崩潰。登錄貓的消息 「ArrayIndexOutOfBoundsException異常長度= 16;指數= 16」
這裏是我的代碼:如何避免ArrayIndexOutOfBoundsException?
public Integer[] mThumbIds = {
R.drawable.pic_1, R.drawable.pic_2,
R.drawable.pic_3, R.drawable.pic_4,
R.drawable.pic_5, R.drawable.pic_6,
R.drawable.pic_7, R.drawable.pic_8,
R.drawable.pic_9, R.drawable.pic_10,
R.drawable.pic_11, R.drawable.pic_12,
R.drawable.pic_13, R.drawable.pic_14,
R.drawable.pic_15, R.drawable.pic_16,
R.drawable.pic_17, R.drawable.pic_18,
R.drawable.pic_19, R.drawable.pic_20,
........ R.drawable.pic_96
};
代碼:
@Override
public View getView(int position, View convertView, ViewGroup parent) {
int width = metrics.widthPixels/6;
int height = metrics.heightPixels/6;
ImageView i;
i = new ImageView(mContext);
i.setLayoutParams(new GridView.LayoutParams(height, height));
i.setScaleType(ImageView.ScaleType.CENTER_CROP);
}
if(mImageSet == IMAGE_SET_ONE) {
Integer[] images1 = new Integer[16];
System.arraycopy(mThumbIds, 0, images1, 0, 16);
i.setImageResource(images1[position]);
} else if(mImageSet == IMAGE_SET_THREE) {
...........
}
return i;
}
請幫助我..
什麼是調用代碼?我認爲它在getItem(int位置) – RNJ
後失敗getView – Blackbelt
數組索引從零開始。所以,一個16元素的數組從0到15. – GriffeyDog