Android “添加到列表时出现Nullpointerexception”;“编辑源查找路径”;

Android “添加到列表时出现Nullpointerexception”;“编辑源查找路径”;,android,gridview,arraylist,Android,Gridview,Arraylist,我正在尝试创建图像的网格视图。我正在复制,但是他们将可绘图项硬编码为整数[],而我必须将我的设置为用户选择的值。mListContents由对象填充。path和pathA都是使用值启动的。这一切都由调试器确认。当它到达mList.add(pathA)时,它抛出一个nullpointerexception。调试时,它在ActivityThread中显示“未找到源”,并提供“编辑源查找路径”选项。从教程Integer[]更改为列表的任何问题 公共类ImageAdapter扩展了BaseAdapter

我正在尝试创建图像的网格视图。我正在复制,但是他们将可绘图项硬编码为
整数[]
,而我必须将我的设置为用户选择的值。mListContents由对象填充。path和pathA都是使用值启动的。这一切都由调试器确认。当它到达
mList.add(pathA)
时,它抛出一个nullpointerexception。调试时,它在ActivityThread中显示“未找到源”,并提供“编辑源查找路径”选项。从教程
Integer[]
更改为
列表
的任何问题

公共类ImageAdapter扩展了BaseAdapter{
私有上下文;
私有内码;
dbdb;
列出目录;
列表列表;
公共图像适配器(上下文c,int-menuId){
mListContents=newarraylist();
mContext=c;
mMenuId=menuId;
db=新的dbhelper(mContext);
集合列表(mMenuId);
setDrawableList();
}
私有void setDrawableList(){
对于(ObjectGeneric项:mListContents){
int path=item.getImagePath();
整数路径A=(整数)路径;
mList.add(路径);
}
}
//为适配器引用的每个项目创建新的ImageView
公共视图getView(int位置、视图转换视图、视图组父视图){
图像视图图像视图;
如果(convertView==null){//如果它没有被回收,初始化一些属性
imageView=新的imageView(mContext);
setLayoutParams(新的GridView.LayoutParams(85,85));
imageView.setScaleType(imageView.ScaleType.CENTER\U裁剪);
设置填充(8,8,8,8);
}否则{
imageView=(imageView)convertView;
}
setImageResource(mList.get(position));
返回图像视图;
}

乍一看,您似乎没有初始化mList,因此空指针异常是正确的。请尝试初始化它,如下所示:

public ImageAdapter(Context c, int menuId) {
    mListContents = new ArrayList<ClothingItem>();
    mList = new ArrayList<Integer>();  // <---  here

    mContext = c;
    mMenuId = menuId;
    db = new dbhelper(mContext);
    setList(mMenuId);
    setDrawableList();
}
公共图像适配器(上下文c,int-menuId){ mListContents=newarraylist();
mList=new ArrayList();//这肯定是它,谢谢。mListContents已启动,但mList未启动!确认后将标记为应答。谢谢!
public ImageAdapter(Context c, int menuId) {
    mListContents = new ArrayList<ClothingItem>();
    mList = new ArrayList<Integer>();  // <---  here

    mContext = c;
    mMenuId = menuId;
    db = new dbhelper(mContext);
    setList(mMenuId);
    setDrawableList();
}