Android - listview with custom adapter fails when new items scrolled into view
<p>Having a slight problem with a listview.  It works fine with one exception: when I scroll down past the bottom of the listview, I get a nullpointerexception. Using the debugger, I have verified that the arraylist is loaded in exactly the correct order and that the date labels are right where they should be. However, once I start scrolling to where a new item has to come into view, I get the error. I'm not sure why this is occurring, and only when the list is scrolled enough so that some elements pop off and others need to come into view.</p>

<pre><code> public class MyCustomBaseAdapter extends BaseAdapter {
 private static ArrayList&lt;Object&gt; searchArrayList;

 private LayoutInflater mInflater;

 public MyCustomBaseAdapter(Context context, ArrayList&lt;Object&gt; results) {

  searchArrayList = results;
  mInflater = LayoutInflater.from(context);
 }

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

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

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

public int getItemViewType(int position) {
    Object item = getItem(position);

    if(item instanceof Appointment) {
        return 0;
    } else {
        // It's a section title:
        return 1;
    }
}

public View getView(int position, View convertView, ViewGroup parent) 
{
    Object item = getItem(position);

    if(convertView == null) 
    {
        // Create item view for first time
        if(item instanceof Appointment) 
        {   // inflate appointment list view item layout
            convertView = mInflater.inflate(R.layout.calendar_item, null);
        } 
        else 
        {   // inflate title section list view item layout
            convertView = mInflater.inflate(R.layout.calendar_item_header, null); 
        }
    }

    // Update list view item view according to type:
    if(item instanceof Appointment) 
    {
        Appointment a = (Appointment) item;

        ViewHolder holder;

        holder = new ViewHolder();
        holder.txtAttendee = (TextView) convertView.findViewById(R.id.attendee);
        holder.txtSummary = (TextView) convertView.findViewById(R.id.summary);
        holder.txtStarts = (TextView) convertView.findViewById(R.id.starts);
        holder.txtEnds = (TextView) convertView.findViewById(R.id.ends);
        holder.txtCategories = (TextView) convertView.findViewById(R.id.categories);

        convertView.setTag(holder);
        convertView.setPadding(4, 4, 4, 16);

        holder.txtAttendee.setText(a.GetAttendee());  // exception here
        holder.txtSummary.setText("&gt;" + a.GetSummary());
        String st = a.GetDTStart().toString();
        String en = a.GetDTEnd().toString();

        holder.txtStarts.setText(st.substring(0,16));
        holder.txtEnds.setText(en.substring(0,16)); 

        String cat = a.GetCategories();
        holder.txtCategories.setText(cat);

    } 
    else if(item instanceof String)
    {
        // Item is a section header string:
        String label = (String) item;
        // Retrieve label TextView from convertView... etc...
        HeaderHolder holder;

        holder = new HeaderHolder();

        holder.txtHeader = (TextView) convertView.findViewById(R.id.header);

        convertView.setTag(holder);
        convertView.setPadding(2,2,2,2);
        convertView.setClickable(false);
        convertView.setFocusable(false);

        holder.txtHeader.setText(" " + label);
    }

    return convertView;
}

 static class ViewHolder 
 {
     TextView txtAttendee;
     TextView txtSummary;
     TextView txtStarts;
     TextView txtEnds;
     TextView txtCategories;
 }

 static class HeaderHolder
 {
     TextView txtHeader;

 }
}
</code></pre>

<p>I get a nullpointerexception at "ViewRoot.deliverKeyEventToViewHierarchy" at line 2414.</p>

<p>What am I doing wrong?  Thanks in advance!</p>
