Crash in ListView at AbsListView.obtainView for ListActivity

前端 未结 4 1733
时光取名叫无心
时光取名叫无心 2020-12-05 06:23

I\'m watching content updates on a ListActivity using a ContentObserver as follows:

protected void onCreate(Bundle savedState)
   {
        super.onCreate(sa         


        
相关标签:
4条回答
  • 2020-12-05 06:54

    I had a similar stack trace and discovered that I was returning a null from my getView() method in certain cases.

    0 讨论(0)
  • 2020-12-05 06:57

    If you are using a static class ViewHolder to store your view items in the adapter, you may forgot to set the viewHolder object as the tag of the convertView. E.g:

    if (convertView == null) {
        LayoutInflater mInflater = (LayoutInflater) context
                    .getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
            convertView = mInflater.inflate(R.layout.adapter_drivers_and_riders, null);
            holder = new ViewHolder();
            holder.tvDate = (TextView)convertView.findViewById(R.id.tvDate);
            holder.tvTime = (TextView)convertView.findViewById(R.id.tvTime);
    
            convertView.setTag(holder);
    
    } else {
        holder = (ViewHolder) convertView.getTag();
    }
    

    In my case, I was not using a Cursor but having the same issue, I figured it out that i forgot to set the tag as viewHolder to convertView so when the first adapter views are created for the listview, it is ok but when you scroll and recycling mechanism works, it crashes since it can't restore the viewHolder from convertView.

    Just in case, I wanted to mention.

    0 讨论(0)
  • 2020-12-05 06:58

    I have not used changeCursor(). And, since the query you used to create the Cursor is the same as the query you are using to "change" the cursor, I'd dump the changeCursor() call outright and just call requery() on the Cursor you have.

    0 讨论(0)
  • 2020-12-05 07:02

    If you have a list and extend BaseAdapter or Adapter to get a custom list, make sure that getView returns a non-null value.

    If you have a tabbed view and one of your fragment is a list that override Adapter/BaseAdapter and getView returns null you will get this problem.

    0 讨论(0)
提交回复
热议问题