Note that there are some explanatory texts on larger screens.

plurals
  1. POandroid.database.CursorIndexOutOfBoundsException: Index -1 requested
    text
    copied!<p>I'm trying to read all the contacts using RawContacts.entityIterator but I'm seeing this error:</p> <p>android.database.CursorIndexOutOfBoundsException: Index -1 requested</p> <p>Following is my code:</p> <pre><code>ContentResolver cr = getContentResolver(); Cursor cur = cr.query(Contacts.CONTENT_URI, null, null, null, null); String id = cur.getString(cur.getColumnIndex(Contacts._ID)); if (cur.getCount() &gt; 0) { while (cur.moveToNext()) { final Uri uri = RawContactsEntity.CONTENT_URI; final String selection = Data.CONTACT_ID + "=?"; final String[] selectionArgs = new String[] {id}; final Map&lt;String, List&lt;ContentValues&gt;&gt; contentValuesListMap = new HashMap&lt;String, List&lt;ContentValues&gt;&gt;(); EntityIterator entityIterator = null; entityIterator = RawContacts.newEntityIterator(cr.query( uri, null, selection, selectionArgs, null)); while (entityIterator.hasNext()) { Entity entity = entityIterator.next(); for (NamedContentValues namedContentValues : entity.getSubValues()) { ContentValues contentValues = namedContentValues.values; String key = contentValues.getAsString(Data.MIMETYPE); if (key != null) { List&lt;ContentValues&gt; contentValuesList = contentValuesListMap.get(key); if (contentValuesList == null) { contentValuesList = new ArrayList&lt;ContentValues&gt;(); contentValuesListMap.put(key, contentValuesList); } contentValuesList.add(contentValues); } } } Log.i(tag, "Contact index=" + id); } } </code></pre> <p>Can somebody please tell me what's wrong with my code.</p>
 

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