Android BitmapFactory.decodefile是否返回null?

Android BitmapFactory.decodefile是否返回null?,android,gridview,arraylist,bitmapfactory,Android,Gridview,Arraylist,Bitmapfactory,我制作了一个包含5个位图的数组列表。为了创建ArrayList,我创建了自己的类。在gridview中显示图像。单击网格视图项时,BitmapFactory.decodeFile返回null,因为未正确返回项的位置。这是代码 物品类别 public class Items { final String name; public final int drawableId; public Items(String name, int drawableId) { this.name = na

我制作了一个包含5个位图的数组列表。为了创建ArrayList,我创建了自己的类。在gridview中显示图像。单击网格视图项时,BitmapFactory.decodeFile返回null,因为未正确返回项的位置。这是代码

物品类别

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

您无法通过此行获取项目位置

String itemPosition = _bitmaps.get(position).toString();
您正在将Item类强制转换为string。您应该这样做以获取对象的“名称”

String itemPosition = _bitmaps.get(position).name;

您是否尝试过清理项目?是否可以发布getView?当我单击grid view的项1时,toast消息会同时返回项1、项2和项3的名称,然后路径错误。您应该给出图像的路径,以便将其解码为位图。
String itemPosition = _bitmaps.get(position).toString();
String itemPosition = _bitmaps.get(position).name;