Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid cursoroutofboundexception
    primarykey
    data
    text
    <p>I am doing a simple app, I have an edittext field and a button, the button has an onclick event. The code is as shown below:</p> <pre><code>private static final int CONTACT_PICKER_RESULT = 1; public void doLaunchContactPicker(View view) { Intent contactPickerIntent = new Intent(Intent.ACTION_PICK, Contacts.CONTENT_URI); startActivityForResult(contactPickerIntent, CONTACT_PICKER_RESULT); } </code></pre> <p>I am calling contacts picker activity, when I select a contact I want to populate the name of the contact in the edittext field.</p> <p>The code for this as shown below:</p> <pre><code> protected void onActivityResult(int requestCode, int resultCode, Intent data) { String contactname = ""; // use the contact provider to get the contact details Uri result = data.getData(); Cursor cursor = getContentResolver().query(result, null, null, null, null); int idx = cursor.getColumnIndexOrThrow(ContactsContract.Contacts._ID); contactname = cursor.getString(idx); EditText name = (EditText) findViewById(R.id.editText1); name.setText(contactname); cursor.close(); } </code></pre> <p>All this code is included in the <code>onCreate()</code> of the main activity.</p> <p>When I run the app in emulator and click on the button I am getting contact list (I have created 3 contacts in the emulator). when I select a contact I am getting an error in DDMS. the error is:</p> <pre><code>06-09 19:24:16.188: ERROR/AndroidRuntime(7158): Caused by: android.database.CursorIndexOutOfBoundsException: Index -1 requested, with a size of 1 </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload