在gridview适配器中,我有以下代码:
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
ViewHolder view;
LayoutInflater inflator = activity.getLayoutInflater();
if(convertView==null)
{
view = new ViewHolder();
convertView = inflator.inflate(R.layout.gridview_row, null);
view.txtViewTitle = (TextView) convertView.findViewById(R.id.date);
view.imgViewFlag = (ImageView) convertView.findViewById(R.id.imageView1);
convertView.setTag(view);
}
else
{
view = (ViewHolder) convertView.getTag();
}
view.txtViewTitle.setText(listCountry.get(position));
view.imgViewFlag.setImageResource(listFlag.get(position));
return convertView;
}
根据我的逻辑,代码应该没问题。但我的logcat中有一个例外。错误描述如下:
在第72行中,该行为:view.imgViewFlag.setImageResource(listFlag.get(position));
如何解决此异常?
答案 0 :(得分:0)
确保你的listFlag不为空并检查你的布局gridview_row是imageview的id是一样的..