开发者

CursorOutOfBounds getting contact phone number?

I keep getting this CursorOutOfBounds error

 10-13 22:30:10.205: ERROR/AndroidRuntime(16659): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1001, result=-1, data=Intent { dat=content://com.a开发者_StackOverflowndroid.contacts/data/229 flg=0x1 (has extras) }} to activity {com.fttech.test2/com.fttech.test2.TestContacts}: android.database.CursorIndexOutOfBoundsException: Index -1 requested, with a size of 0
10-13 22:30:10.205: ERROR/AndroidRuntime(16659):     at android.app.ActivityThread.deliverResults(ActivityThread.java:2655)
10-13 22:30:10.205: ERROR/AndroidRuntime(16659): Caused by: android.database.CursorIndexOutOfBoundsException: Index -1 requested, with a size of 0
10-13 22:30:10.205: ERROR/AndroidRuntime(16659):     at android.database.AbstractCursor.checkPosition(AbstractCursor.java:580)
-13 22:30:10.205: ERROR/AndroidRuntime(16659):     at android.database.AbstractWindowedCursor.checkPosition(AbstractWindowedCursor.java:214)

I am using this code onActivityREsult to return the contact selected.

protected void onActivityResult(int requestCode, int resultCode, Intent data) {

switch (requestCode) {
case (CONTACT_PICKER_RESULT) :
if (resultCode == Activity.RESULT_OK) {
Uri contactData = data.getData();
 Cursor cursor =  managedQuery(contactData, null, null, null, null);


while (cursor.moveToNext()) 
                {           
String contactId = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts._ID));
Log.v("Contact_ID", contactId);
name = cursor.getString(cursor.getColumnIndexOrThrow(ContactsContract.Contacts.DISPLAY_NAME)); 
Log.v("NAME", name);
Cursor phones = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null,ContactsContract.CommonDataKinds.Phone.CONTACT_ID +" = "+ contactId,null, null);
                   phoneNumber = phones.getString(phones.getColumnIndexOrThrow(ContactsContract.CommonDataKinds.Phone.NUMBER));


            }
            ContactInfo.setText("Contact: " + name + "./n" + " Phone Number: "+ phoneNumber);
             }
          }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜