title: java.lang.NullPointerException: Attempt to read from field 'android.widget.TextView
body: <p>Hello I realize there are multiple people with a similar issue but the reason for me adding this as a new question is because this is an adapter with two holders. I have a <code>listview</code> that has a header cell and the information cell. the error that I am encountering its <br></p>
  
  <blockquote>
    <p>java.lang.NullPointerException: Attempt to read from field 'android.widget.TextView.</p>
  </blockquote>
  
  <p>Which only happens when I scroll the list down and then go back up. I am assuming the <code>holder</code> is getting destroyed and when I call the line to add text the holder is null but I am not sure. Thank you for your help in advance!</p>
  
  <p>Custom Adapter:</p>
  
  <pre><code>private class MyCustomAdapter extends ArrayAdapter&lt;sources&gt; {
  
      private ArrayList&lt;sources&gt; sources_list = new ArrayList&lt;sources&gt;();
      private TreeSet&lt;Integer&gt; sectionHeader = new TreeSet&lt;Integer&gt;();
      private static final int TYPE_ITEM = 0;
      private static final int TYPE_SEPARATOR = 1;
      private LayoutInflater vi;
  
      public MyCustomAdapter(Context context, int textViewResourceId, ArrayList&lt;sources&gt; sources_list) {
          super(context, textViewResourceId, sources_list);
          vi = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
      }
  
      public void addItem(final sources item) {
          sources_list.add(item);
          notifyDataSetChanged();
      }
  
      public void addSectionHeaderItem(final sources item) {
          sources_list.add(item);
          sectionHeader.add(sources_list.size() - 1);
          notifyDataSetChanged();
      }
  
      public int getItemViewType(int position) {
          return sectionHeader.contains(position) ? TYPE_SEPARATOR : TYPE_ITEM;
      }
  
      public int getCount() {
          return sources_list.size();
      }
  
      public int getViewTypeCount() {
          return 2;
      }
  
      public sources getItem(int position) {
          return sources_list.get(position);
      }
  
      @Override
      public long getItemId(int position) {
          return position;
      }
  
      public class ViewHolder {
          TextView code;
          CheckBox name;
      }
  
      public class ViewHolder2 {
          TextView separator;
      }
  
      @Override
      public View getView(int position, View convertView, ViewGroup parent) {
          ViewHolder holder = null;
          ViewHolder2 holder2 = null;
          Log.v("ConvertView", String.valueOf(position));
          int rowType = getItemViewType(position);
          if (convertView == null) {
              switch (rowType) {
                  case TYPE_ITEM:
                      convertView = vi.inflate(R.layout.source_cell, null);
                      holder = new ViewHolder();
                      holder.code = (TextView)
                              convertView.findViewById(R.id.code);
                      holder.name = (CheckBox)
                              convertView.findViewById(R.id.checkBox1);
                      break;
  
                  case TYPE_SEPARATOR:
                      holder2 = new ViewHolder2();
                      convertView = vi.inflate(R.layout.source_header, null);
                      holder2.separator = (TextView)
                              convertView.findViewById(R.id.separator);
                      break;
              }
  
              convertView.setTag(holder);
  
          } else {
              if (rowType == TYPE_ITEM) {
                  holder = (ViewHolder)
                          convertView.getTag(R.layout.source_cell);
              } else {
                  holder2 = (ViewHolder2) convertView.getTag(R.layout.source_header);
              }
  
          }
  
          if (rowType == TYPE_ITEM) {
              sources n_source = sources_list.get(position);
              holder.code.setText(n_source.getCode().toUpperCase());
              holder.name.setTag(n_source);
          } else {
              sources n_source = sources_list.get(position);
              holder2.separator.setText(n_source.getCode().toUpperCase());
          }
          return convertView;
      }
  }
  </code></pre>