以下は私のコードです。android.database.CursorIndexOutOfBoundsException
:インデックス-1が要求され、サイズ2のエラーが発生しました。それを解決する方法を教えてもらえますか?android.database.CursorIndexOutOfBoundsException:インデックス-1が要求されました。サイズは2です。
ContentResolver cr = getContentResolver();
Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI,
null, null, null, null);
if (Integer.parseInt(cur.getString(
cur.getColumnIndex(People.PRIMARY_PHONE_ID))) > 0) {
Cursor pCur = cr.query(
Contacts.Phones.CONTENT_URI,
null,
Contacts.Phones.PERSON_ID +" = ?",
new String[]{id}, null);
int i=0;
int pCount = pCur.getCount();
String[] phoneNum = new String[pCount];
String[] phoneType = new String[pCount];
while (pCur.moveToNext()) {
phoneNum[i] = pCur.getString(
pCur.getColumnIndex(Contacts.Phones.NUMBER));
phoneType[i] = pCur.getString(
pCur.getColumnIndex(Contacts.Phones.TYPE));
i++;
}
}
}
}
「phoneType」とは何ですか?また、質問を編集してコードを正しくフォーマットする必要があります。 – Falmarri
このエラーが発生している可能性がありますあなたはウルトラエミュレータで連絡先を追加していないbcoz .......... –
あなたはAndroidManifestに適切な権限を追加しましたか? – Sriram