我正在尝试查询默认电话内容提供商的电话号码并将由此获得的值存储到 ArrayList ar = new ArrayList(); 光标 cur = cr.query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null);
if (cur.getCount() > 0){
while (cur.getCount() > 0){
while(cur.moveToNext()){
//unique id
String id = cur.getString(cur.getColumnIndex(ContactsContract.Contacts._ID));
//number corresponding to the id
String name = cur.getString(cur.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
//lets check if this guy even has a number saved
if(Integer.parseInt(cur.getString(cur.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER))) > 0){
//Query here
//Get the phone numbers!
Cursor pCur = cr.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null,
ContactsContract.CommonDataKinds.Phone.CONTACT_ID + "=?",
new String[]{id},null);
while(pCur.moveToNext()){
ar.add((pCur.getString(pCur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER))));
}
Log.d("String Report", ar.get(5));
pCur.close();
}
但是,这会在 Log.d 方法中给出数组越界错误。由于某种原因,只有一个值被存储在内部,即 我只得到 ar.get(0) 作为有效输出。我在犯什么错误??