Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8629187
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T08:44:15+00:00 2026-06-12T08:44:15+00:00

i want to pick phone number from contact list i write this code to

  • 0

i want to pick phone number from contact list
i write this code to pick phone number but this throw exception

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (resultCode == RESULT_OK) {
            switch (requestCode) {
            case CONTACT_PICKER_RESULT:
                Bundle extras = data.getExtras();
                Set<String> keys = extras.keySet();
                Iterator<String> iterate = keys.iterator();
                while (iterate.hasNext()) {
                    String key = iterate.next();
                    Log.v("R", key + "[" + extras.get(key) + "]");
                }
                Uri result = data.getData();
                Cursor c = getContentResolver().query(result,null,null,null,null);
                try {
                    c.moveToFirst();
                    String name = c
                            .getString(c
                                    .getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
                    Log.i("name", name);
                    String contactId = c.getString(c
                            .getColumnIndex(ContactsContract.Contacts._ID));
                    Log.i("Contact Id : ", contactId);
                    Cursor phones = getContentResolver().query(
                            ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
                            null,
                            ContactsContract.CommonDataKinds.Phone.CONTACT_ID
                                    + " = " + contactId, null, null);
                    final String[] contactNumbers = new String[phones
                            .getCount()];
                    int count = 0;
                    while (phones.moveToNext()) {
                        contactNumbers[count] = phones
                                .getString(phones
                                        .getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
                        count++;
                    }
                    phones.close();

                    if (contactNumbers.length > 1 ) {
                        AlertDialog.Builder builder = new AlertDialog.Builder(this);
                        builder.setTitle("Call Number");
                        builder.setItems(contactNumbers, new OnClickListener() {
                            public void onClick(DialogInterface dialog, int which) {
                                ContactActivity.roamNumber
                                        .setText(contactNumbers[which]);

                            }
                        });

                        builder.create().show();

                    } else {
                        ContactActivity.roamNumber
                        .setText(contactNumbers[0]);
                    }

                } finally {
                    c.close();
                }

                break;
            }

        } else {
            // gracefully handle failure
            Log.i("", "Warning: activity result not ok");
        }


    }

note: my phone sync with Facebook when chose any Facebook contact to give me number throw exception:

10-01 13:44:17.369: E/AndroidRuntime(9991): FATAL EXCEPTION: main
10-01 13:44:17.369: E/AndroidRuntime(9991): java.lang.RuntimeException: Failure delivering result ResultInfo{who=Contact, request=1001, result=-1, data=Intent { dat=content://com.android.contacts/contacts/lookup/543r3759-2D333B2D45513B2D373D41.1160i730738002/3838 flg=0x1 (has extras) }} to activity {com.xeno.callRoaming/com.xeno.callRoaming.XenoCallRoamingActivity}: android.database.CursorIndexOutOfBoundsException: Index 0 requested, with a size of 0
10-01 13:44:17.369: E/AndroidRuntime(9991):     at android.app.ActivityThread.deliverResults(ActivityThread.java:2536)
10-01 13:44:17.369: E/AndroidRuntime(9991):     at android.app.ActivityThread.handleSendResult(ActivityThread.java:2578)
10-01 13:44:17.369: E/AndroidRuntime(9991):     at android.app.ActivityThread.access$2000(ActivityThread.java:117)
10-01 13:44:17.369: E/AndroidRuntime(9991):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:965)
10-01 13:44:17.369: E/AndroidRuntime(9991):     at android.os.Handler.dispatchMessage(Handler.java:99)
10-01 13:44:17.369: E/AndroidRuntime(9991):     at android.os.Looper.loop(Looper.java:123)
10-01 13:44:17.369: E/AndroidRuntime(9991):     at android.app.ActivityThread.main(ActivityThread.java:3687)
10-01 13:44:17.369: E/AndroidRuntime(9991):     at java.lang.reflect.Method.invokeNative(Native Method)
10-01 13:44:17.369: E/AndroidRuntime(9991):     at java.lang.reflect.Method.invoke(Method.java:507)
10-01 13:44:17.369: E/AndroidRuntime(9991):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
10-01 13:44:17.369: E/AndroidRuntime(9991):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
10-01 13:44:17.369: E/AndroidRuntime(9991):     at dalvik.system.NativeStart.main(Native Method)
10-01 13:44:17.369: E/AndroidRuntime(9991): Caused by: android.database.CursorIndexOutOfBoundsException: Index 0 requested, with a size of 0
10-01 13:44:17.369: E/AndroidRuntime(9991):     at android.database.AbstractCursor.checkPosition(AbstractCursor.java:580)
10-01 13:44:17.369: E/AndroidRuntime(9991):     at android.database.AbstractWindowedCursor.checkPosition(AbstractWindowedCursor.java:214)
10-01 13:44:17.369: E/AndroidRuntime(9991):     at android.database.AbstractWindowedCursor.getString(AbstractWindowedCursor.java:41)
10-01 13:44:17.369: E/AndroidRuntime(9991):     at android.database.CursorWrapper.getString(CursorWrapper.java:135)
10-01 13:44:17.369: E/AndroidRuntime(9991):     at com.xeno.callRoaming.ContactPickerActivity.onActivityResult(ContactPickerActivity.java:67)
10-01 13:44:17.369: E/AndroidRuntime(9991):     at android.app.ActivityGroup.dispatchActivityResult(ActivityGroup.java:119)
10-01 13:44:17.369: E/AndroidRuntime(9991):     at android.app.ActivityThread.deliverResults(ActivityThread.java:2532)
10-01 13:44:17.369: E/AndroidRuntime(9991):     ... 11 more

what is the problem ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T08:44:16+00:00Added an answer on June 12, 2026 at 8:44 am

    i solve the problem use this code :

    Uri result = data.getData();
    
                    Cursor c = getContentResolver().query(result, null, null, null,
                            null);
                    Log.d("Row Count c", c.getCount() +"");
                    Log.d("result", result +"");
    
                    try {
                        c.moveToFirst();
                        String name = c
                                .getString(c
                                        .getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
                        Log.i("name", name);
    
                        String contactId = c.getString(c
                                .getColumnIndex(ContactsContract.Contacts._ID));
                        Log.i("Contact Id : ", contactId);
                        Cursor phoness = getContentResolver().query(
                                ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
                                new String[]{ContactsContract.CommonDataKinds.Phone.NUMBER},
                                ContactsContract.CommonDataKinds.Phone.CONTACT_ID
                                        + " = " + contactId, null, null);
                        Cursor phones = managedQuery(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
                                new String[]{ContactsContract.CommonDataKinds.Phone.NUMBER}, 
                                ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME  +
                                " like ('"+name+"')", null, null);
    
    
                        if (phones.getCount() == 0) {
                            AlertDialog.Builder numbersBuilder = new AlertDialog.Builder(this);
                            numbersBuilder.setMessage("No Number Found ..!")
                            .setCancelable(true);
                            AlertDialog alert = numbersBuilder.create();
                            alert.show();
                            ContactActivity.roamNumber
                            .setText("");
                            break;
                        }
    
                        final String[] contactNumbers = new String[phones
                                .getCount()];
                        int count = 0;
                        while (phones.moveToNext()) {
                            contactNumbers[count] = phones
                                    .getString(phones
                                            .getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
                            count++;
                        }
                        phones.close();
    
                        if (contactNumbers.length > 1 ) {
                            AlertDialog.Builder builder = new AlertDialog.Builder(this);
                            builder.setTitle("Call Number");
                            builder.setItems(contactNumbers, new OnClickListener() {
                                public void onClick(DialogInterface dialog, int which) {
                                    ContactActivity.roamNumber
                                            .setText(contactNumbers[which]);
    
                                }
                            });
    
                            builder.create().show();
    
                        } else {
                            ContactActivity.roamNumber
                            .setText(contactNumbers[0]);
                         }
    
    
                    } finally {
                        c.close();          
                          }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have made an application which calls the phone's contact list but i want
My asp.net site allows users to pick the theme they want from a list
I want to pick photo from contacts . I got below code from stack
I am using intent to display contact list. From contacts I want to get
So ordinarily the element I want to pick from a list would be populated
I want to pick all directory URLs from this site . I did the
I have referred this code to display contact list. and it is working fine
I want my application to pick a video from the gallery. It uses following
Basically, I want to get a list of all installed apps and pick one
I want to pick up date from screen, add 1 day and put back

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.