我做了一个5位图的ArrayList。为了创建一个ArrayList,我创建了自己的类。在gridview中显示图像。当我点击网格查看项目时,BitmapFactory.decodeFile()返回null,因为项目的位置没有正确返回。下面是代码BitmapFactory.decodefile返回null?
Items.class
public class Items {
final String name;
public final int drawableId;
public Items(String name, int drawableId) {
this.name = name;
this.drawableId = drawableId;
}
}
ArrayList和添加图像在它
ArrayList<Items> bitmaps = new ArrayList<Items>();
bitmaps.add(new Items("image_name", R.drawable.image1));
在示出图像
ArrayList<Items> _bitmaps;
.....
String itemPosition = _bitmaps.get(position).toString();
Log.d("POS", "Item Position: " + itemPosition);
Bitmap bitmap = BitmapFactory.decodeFile(itemPosition, options);
imgDisplay.setImageBitmap(bitmap);
通知的Log.d.的时间为GridView的第一项即位置0,它返回,
08-31 02:11:47.125: D/POS(943): Item Position: [email protected]
您是否尝试过清理您的项目? – 2014-08-30 21:58:09
是的。但是同样的错误 – user3864752 2014-08-30 22:09:50
你可以发布'getView'吗? – mmlooloo 2014-08-31 02:06:09