title: How do you get the members of a contact group?
body: <p>I have the ID of a contact group, and I'd like to list its members. Here's the code I'm trying:</p>
  
  <pre><code>String[] projection = new String[]{
      ContactsContract.CommonDataKinds.GroupMembership.CONTACT_ID 
  };
  Cursor contacts = getContentResolver().query(
          Data.CONTENT_URI,
          projection,
          ContactsContract.CommonDataKinds.GroupMembership.GROUP_ROW_ID + "=" + gid,
          null,
          null
  );
  String result = "";
  do {
      result += contacts.getString(contacts.getColumnIndex(ContactsContract.CommonDataKinds.GroupMembership.CONTACT_ID)) + " ";
  } while (contacts.moveToNext());
  </code></pre>
  
  <p>But this throws an Exception:</p>
  
  <pre><code>03-24 17:11:33.097: ERROR/AndroidRuntime(10730): android.database.CursorIndexOutOfBoundsException: Index -1 requested, with a size of 2
  ...
  03-24 17:11:33.097: ERROR/AndroidRuntime(10730):     at myapp.MultiSend$1.onItemClick(MultiSend.java:83)
  </code></pre>
  
  <p>which is the line starting <code>result +=</code>. Can anyone tell me what I'm doing wrong, or suggest a better way to get the same information?</p>