title: Contents data in a list view
body: <p>I want to get all of the records of list view content. I have used row.setonclicklistner but the first 3-4 items are working fine and the next item shows null pointer exception. What should I do?
  I have pointed that particular line using (*).</p>
  
  <pre><code>package com.example.tex.list;
  public class tex extends Activity {
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
  
      setContentView(R.layout.activity_xutex);
      ListView lt=(ListView)findViewById(R.id.listView1);
  
      Databasequery db =  new Databasequery(this);
      db.open();
      List&lt;Propertiess&gt;test= db.getAllcards();
      lt.setAdapter(new myadatper(getApplicationContext(),R.layout.listlayoutdesign, test));
  
  
  }
  
  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
      getMenuInflater().inflate(R.menu.activity_xutex, menu);
      return true;
  }
  
   public class myadatper extends ArrayAdapter&lt;Propertiess&gt;
  {
  List&lt;Propertiess&gt; items;
  
  LayoutInflater mInflater ; 
  
  Context context;
  
  int layoutResourceId; 
  Propertiess p;
  
  public myadatper(Context context, int layoutResourceId,
            List&lt;Propertiess&gt;items)
          {
         super(context, layoutResourceId, items);
  
          this.layoutResourceId=layoutResourceId;
  
          this.items = items;
  
          this.context=context;
           // TODO Auto-generated constructor stub
          }
  
  
          @Override
          public View getView(final int position, View convertView, ViewGroup parent)
          {
           // TODO Auto-generated method stub
           //return super.getView(position, convertView, parent);
  
           View row = convertView;
           ViewHolder holder = new ViewHolder();
  
           if(row==null)
           {
  
  
            LayoutInflater inflater=getLayoutInflater();
            row=inflater.inflate(R.layout.listlayoutdesign, parent, false);        
            holder.name = (TextView) row.findViewById(R.id.TextView01);
            holder.address = (TextView) row.findViewById(R.id.TextView02);
            holder.designation=(TextView)row.findViewById(R.id.TextView03);
            holder.contactno=(TextView)row.findViewById(R.id.textView1);
            holder.Emailaddress=(TextView)row.findViewById(R.id.TextView04);
            holder.TapToadd=(ImageView)row.findViewById(R.id.imageView1);
  
            row.setTag(holder);
  
      row.setOnClickListener(new View.OnClickListener() {
  
              public void onClick(View v) {       
                  // TODO Auto-generated method stub
  
                  ListView l3t=(ListView)findViewById(R.id.listView1);
                  View view = l3t.getChildAt(position);
          Exception Point      ******************TextView t = (TextView)view.findViewById(R.id.TextView01);******************
                    TextView t2 = (TextView)view.findViewById(R.id.TextView02);
                   TextView t3=(TextView)view.findViewById(R.id.TextView03);
                   String data=t.getText().toString();
                  Toast.makeText(getApplicationContext(), data, Toast.LENGTH_SHORT).show();
  
              }
          });
  
  
  
           }
  
  
           else
           {
  
                  holder=(ViewHolder)row.getTag();
  
  
           }
  
                  String name=items.get(position).getCompanyname();
                  String contactno=items.get(position).getCompanycontactno();
                  String address=items.get(position).getCompanyaddress();
                  String designation=items.get(position).getCompanyempdesignation();
                  String Emailaddress=items.get(position).getCompanyemailaddress();
                  holder.name.setText(name);
                  holder.contactno.setText(contactno);
                  holder.designation.setText(designation);
                  holder.address.setText(address);
                  holder.Emailaddress.setText(Emailaddress);
  
                  int Datacount=items.size();
                  if(position==Datacount-1)
                  {
                  Toast.makeText(getApplicationContext(), Datacount+"", Toast.LENGTH_SHORT).show();
                  holder.TapToadd.setBackgroundResource(R.drawable.taptoadd);
                  }
  
                  Toast.makeText(getApplicationContext(), position+"", Toast.LENGTH_SHORT).show();
                  return row;
  
  }
  
                    public class ViewHolder
                    {
  
                        TextView name;
                        TextView address;
                        TextView designation;
                        TextView contactno;
                        TextView Emailaddress;
                        ImageView TapToadd;
                        Object obj;
  
  
                    }
        }
   }
  </code></pre>