title: android custom contacts view
body: <p>i'm trying to create a custom Contacts view for an app on android.
  the following code is something i found on a website while searching the topic.
  i'm getting an exception and i don't know why.</p>
  
  <p>this is the contact class:</p>
  
  <pre><code>public class Contact {
  public Contact(long id, String name, String photo) {
      this.id = id;
      this.name = name;
      this.photo = photo;
  }
  public long id;
  public String name;
  public String photo;
  public long getId() {
      return id;
  }
  public void setId(long id) {
      this.id = id;
  }
  public String getName() {
      return name;
  }
  public void setName(String name) {
      this.name = name;
  }
  public String getPhoto() {
      return photo;
  }
  public void setPhoto(String photo) {
      this.photo = photo;
  }
  }
  </code></pre>
  
  <p>this is the adapter's code:</p>
  
  <pre><code>public class ContactsAdapter extends BaseAdapter {
  Vector&lt;Contact&gt; contactList;
  Activity activity;
  
  public ContactsAdapter(Activity activity){
      this.activity = activity;
      fillContacts();
  }
  
  public void fillContacts() {
      Uri uri = ContactsContract.Contacts.CONTENT_URI;
      String[] projection = { ContactsContract.Contacts._ID,
              ContactsContract.Contacts.DISPLAY_NAME,
              ContactsContract.Contacts.PHOTO_ID };
      Cursor cursor = activity.managedQuery(uri, projection, null, null, null);
      contactList = new Vector&lt;Contact&gt;();
      if (cursor.moveToFirst()){
          do {
              contactList.add(new Contact(cursor.getLong(cursor.getColumnIndex(projection[0])), cursor.getString(cursor.getColumnIndex(projection[1])), cursor.getString(cursor.getColumnIndex(projection[2]))));
          }while (cursor.moveToNext());
      }
  }
  
  @Override
  public int getCount() {
      return contactList.size();
  }
  
  @Override
  public Object getItem(int position) {
      return null;
  }
  
  @Override
  public long getItemId(int position) {
      return contactList.get(position).id;
  }
  
  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
      View view = convertView;
      if (view==null){
          LayoutInflater li = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
          view = li.inflate(R.layout.contact, parent);
      }
  
      TextView contactName = (TextView)view.findViewById(R.id.etName);
      ImageView contactPhoto = (ImageView) view.findViewById(R.id.ivPhoto);
      CheckBox checkBox = (CheckBox) view.findViewById(R.id.checkBox1);
      contactName.setText(contactList.get(position).name);
  
      if (contactList.get(position).photo == null){
          contactPhoto = (ImageView) view.findViewById(R.id.ivPhoto);
          contactPhoto.setImageResource(R.drawable.ic_launcher);
      }else{
          Uri contactUri = ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI, contactList.get(position).id);
          Uri contactPhotoUri = Uri.withAppendedPath(contactUri, Contacts.Photo.CONTENT_DIRECTORY);
          contactPhoto.setImageURI(contactPhotoUri);
      }
      return view;
  }
  
  }
  </code></pre>
  
  <p>and this is the activity code:</p>
  
  <pre><code>public class ContactsActivity extends Activity {
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.contacts);
      ContactsAdapter ca = new ContactsAdapter(this);
      ListView contacts = (ListView) findViewById(R.id.lvContacts);
      contacts.setAdapter(ca);
  }
  }
  </code></pre>
  
  <p>can anyone see the problem?</p>