Primary Data is only coming?
<p>I am trying to access the Details of the contacts but I get only the primary details , I am using the Ecliar platform that means,</p>

<p>Now I get the <strong>name, number</strong> and the <strong>email</strong> ID of all contacts using this code.But If a contact having 2 numbers and 2 email IDs I get only the primary <strong>number and Email ID</strong></p>

<p>I am using the display in the ListView like </p>

<p>1.Name 1, Number 1, email id 1.</p>

<p>2.Name 1, Number2, email Id 2. for the first person and so on</p>

<p>3.Name 2, number 1, email Id 1 for second person and so on.will continue like this.</p>

<p>But I get only the number1 and email ID 1 of a particular contact. Didn't get the number 2 and email id2 of that contact.</p>

<p>I edited the loop logic but it went to some other errors. How to solve this problem ?</p>

<p><strong>Code</strong></p>

<pre><code>public class Details extends Activity {

ListView lvItem;
private Button btnAdd;
String emailAddress = "" ; 
String  displayName  = "" ;
String phoneNumber  = "" ; 
ArrayList&lt;String&gt; contactlist=new ArrayList&lt;String&gt;();
ArrayAdapter&lt;String&gt; itemAdapter;


@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
   lvItem = (ListView)this.findViewById(R.id.listview);  
   btnAdd = (Button)this.findViewById(R.id.btn);
   itemAdapter = new ArrayAdapter&lt;String&gt;(this, android.R.layout.simple_list_item_1,contactlist);
   lvItem.setAdapter(itemAdapter);
   btnAdd.setOnClickListener(new View.OnClickListener() {
       public void onClick(View v) {
          readContacts();

       }
   }); 
}


 private void readContacts()
{
    ContentResolver cr =getContentResolver();
    Cursor cursor = cr.query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null);
    while (cursor.moveToNext()) 
    {
        displayName  = "" ;
           ArrayList&lt;String&gt; phoneNumber  = new ArrayList&lt;String&gt;();
           ArrayList&lt;String&gt; emailAddress  = new ArrayList&lt;String&gt;();

        displayName = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));       
        String id = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts._ID));

        Cursor emails = cr.query(Email.CONTENT_URI,null,Email.CONTACT_ID + " = " + id, null, null);
        while (emails.moveToNext()) 
        { 
            emailAddress.add(emails.getString(emails.getColumnIndex(Email.DATA)));
            break;
        }
        emails.close(); 
        if(Integer.parseInt(cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER))) &gt; 0)
        {
            Cursor pCur = cr.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,null,ContactsContract.CommonDataKinds.Phone.CONTACT_ID +" = ?",new String[]{id}, null);
            while (pCur.moveToNext()) 
            {
                 phoneNumber.add(pCur.getString(pCur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER)));
              break;  
            }  
            pCur.close();  
        }   

int phoneNumberCount = phoneNumber.size();
int emailCount = emailAddress.size();

// Add arraylist data to contactlist..

if(phoneNumberCount &gt; emailCount) {

    for (int i=0; i&lt;=phoneNumberCount; i++)
      {
        if(emailCount&gt;i)
          {
           contactlist.add(displayName + " , " + phoneNumber.get(i) + " , " + emailAddress.get(i)+"\n");  
           }
        else
        {
          contactlist.add(displayName + " , " + phoneNumber.get(i)+"\n");
        }
       }
    }
    else 
       {
        for (int i=0; i&lt;=emailCount; i++)
         {
        if(phoneNumberCount&gt;i)
          {
            contactlist.add(displayName+", "+phoneNumber.get(i)+", "+ emailAddress.get(i)+"\n");
          }
        else
        {
            contactlist.add(displayName+","+ emailAddress.get(i)+"\n");
        } 
      }
    }     
    }
    Collections.sort(contactlist);
    itemAdapter.notifyDataSetChanged();
    cursor.close(); 

 }
  }
</code></pre>

<p>Any Solution ?</p>

<p><strong>LogCat</strong></p>

<pre><code>06-19 11:28:08.058: W/KeyCharacterMap(265): No keyboard for id 0
06-19 11:28:08.068: W/KeyCharacterMap(265): Using default keymap:     /system/usr/keychars/qwerty.kcm.bin
06-19 11:28:33.187: D/dalvikvm(265): GREF has increased to 201
06-19 11:33:32.118: W/KeyCharacterMap(307): No keyboard for id 0
06-19 11:33:32.118: W/KeyCharacterMap(307): Using default keymap: /system/usr/keychars/qwerty.kcm.bin
06-19 14:16:35.488: D/AndroidRuntime(385): Shutting down VM
06-19 14:16:35.498: W/dalvikvm(385): threadid=3: thread exiting with uncaught exception (group=0x4001b188)
06-19 14:16:35.498: E/AndroidRuntime(385): Uncaught handler: thread main exiting due to uncaught exception
06-19 14:16:35.507: E/AndroidRuntime(385): java.lang.IndexOutOfBoundsException: Invalid location 1, size is 1
06-19 14:16:35.507: E/AndroidRuntime(385):  at java.util.ArrayList.get(ArrayList.java:341)
06-19 14:16:35.507: E/AndroidRuntime(385):  at com.abhi.Trial3.readContacts(Trial3.java:100)
06-19 14:16:35.507: E/AndroidRuntime(385):  at com.abhi.Trial3.access$0(Trial3.java:44)
06-19 14:16:35.507: E/AndroidRuntime(385):  at com.abhi.Trial3$1.onClick(Trial3.java:38)
06-19 14:16:35.507: E/AndroidRuntime(385):  at android.view.View.performClick(View.java:2364)
06-19 14:16:35.507: E/AndroidRuntime(385):  at android.view.View.onTouchEvent(View.java:4179)
06-19 14:16:35.507: E/AndroidRuntime(385):  at android.widget.TextView.onTouchEvent(TextView.java:6541)
</code></pre>
