Android ArrayIndexOutOfBoundsException异常?

时间:2014-01-13 09:24:58

标签: android

public class GridAllUserAdapter  extends BaseAdapter{

private LayoutInflater _mInflater = null;
private ArrayList<Object>_alluserlist=null;
private Activity _activity = null;
TabGroupActivity parentActivity = null;
ImageLoader imageLoader=null;


/**
 * @param activity
 * @param itemList
 */
public GridAllUserAdapter(Activity activity, ArrayList<Object> itemList) {
    this._activity = activity;
    this._alluserlist = itemList;

    imageLoader=new ImageLoader(_activity);
    _mInflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    parentActivity=(TabGroupActivity)_activity.getParent();
}

public int getCount() {
    return _alluserlist.size();
}

public Object getItem(int position) {
    return _alluserlist.get(position);
}

public long getItemId(int position) {
    return position;
}

static class ViewHolder {
    public ImageView imgViewFlag;
    public TextView txtViewTitle;
}

public View getView(final int position, View convertView, ViewGroup parent) {
    final ViewHolder holder;
    if (convertView == null) {

        convertView = _mInflater.inflate(R.layout.custom_gridview_row, null);
        holder = new ViewHolder();
        holder.txtViewTitle = (TextView) convertView.findViewById(R.id.pic_name_txt);
        holder.imgViewFlag = (ImageView) convertView.findViewById(R.id.photo_frameImg);
        convertView.setTag(holder);
    } else {
        holder = (ViewHolder) convertView.getTag();
    }

    final AllBean bean=(AllBean)_alluserlist.get(position);
    holder.txtViewTitle.setText(bean.getusername());

    imageLoader.DisplayImage(bean.getprofile_photo(), R.drawable.default_profile_pic, holder.imgViewFlag);
    return convertView;
}

// Filter Class
public void filter(String charText) {
    charText = charText.toLowerCase(Locale.getDefault());
    _alluserlist.clear();
    if (charText.length() == 0) {
        _alluserlist.addAll(_alluserlist);
    } else {
        for (Object bean : _alluserlist) {
            if (((AllBean) bean).getusername().toLowerCase(Locale.getDefault())
                    .contains(charText)) {
                _alluserlist.add(bean);

            }
        }
    }
    notifyDataSetChanged();
}
}

我有gridview,其中数据来自服务器。当我点击按钮时,数据显示,突然我的应用程序停止。它在getview上给了我ArrayIndexOutOfBoundsException ..,适配器..,请帮帮我..

1 个答案:

答案 0 :(得分:2)

您指示单击数据时发生崩溃。由于您可以看到所有列表及其中的数据,因此问题不在于您的适配器。您应该发布列表项单击事件。您可能正在使用_alluserlist数组执行某些操作,这会导致崩溃。