如何在CustomList中解决NullPointerException

时间:2015-04-25 21:50:36

标签: java android

这是我的querysetobject.sql班级

CustomList:

CustomList

这是我的public class CustomList extends ArrayAdapter<String> { private final Activity context; private final String[] web; private final Integer[] imageId; public CustomList(Activity context,String[] web, Integer[] imageId) { super(context, R.layout.single_row, web); this.context = context; this.web = web; this.imageId = imageId; } @Override public View getView(int position, View view, ViewGroup parent) { LayoutInflater inflater = context.getLayoutInflater(); View rowView= inflater.inflate(R.layout.single_row, null, true); TextView txtTitle = (TextView) rowView.findViewById(R.id.txt); ImageView imageView = (ImageView) rowView.findViewById(R.id.img); txtTitle.setText(web[position]); imageView.setImageResource(imageId[position]); return rowView; } } 数组,通过imageId循环填充它,如下所示

while

但是当我运行它时,我发现我的while(crs.moveToNext()){ String img = crs.getString(crs.getColumnIndex("Icon")); try { imageId[i] = Integer.parseInt(img); } catch(NumberFormatException nfe) {} i++; } 中的错误在我的课程结束后在我的行上说错误

CustomList

logcat:

imageView.setImageResource(imageId[position]);

1 个答案:

答案 0 :(得分:0)

似乎imageViewimageIdnull。请仔细检查您是否正确设置imageId值,single_row布局的ImageView ID为img