---
title: "CursorIndexOutOfBoundsException for table and records existing"  
description: "CursorIndexOutOfBoundsException for table and records existing"  
author: "Mark Devid"  
published: 2013-05-30  
updated: 2013-05-30  
canonical: https://www.mindstick.com/forum/943/cursorindexoutofboundsexception-for-table-and-records-existing  
category: "android"  
tags: ["android"]  
reading_time: 2 minutes  

---

# CursorIndexOutOfBoundsException for table and records existing

Hi [Expert](https://www.mindstick.com/articles/13120/an-expert-financial-advice-will-improve-your-finances)!\
I am querying the [database](https://www.mindstick.com/articles/12226/use-of-database-in-sencha-extjs-and-insert-record-from-user-form-using-ajax) with the following query:\
final [Cursor](https://www.mindstick.com/articles/13003/create-a-simple-cursor-in-sql-server) subject_cursor = db.rawQuery("[SELECT](https://www.mindstick.com/forum/160534/orderby-then-select-vs-select-then-orderby-performance) * FROM " + DB.Table.SUBJECT + " WHERE uniqueSUB = '" + cs_cursor.getString(1) + "'", null);when i log the cursor [count](https://www.mindstick.com/forum/157774/selecting-count-with-distinct) it gives me 1 as the count, but when i try to [access the data](https://answers.mindstick.com/qa/40056/what-is-the-weo-update-and-how-can-i-access-the-data) using subject_cursor.getString(0) it gives me an [error](https://yourviews.mindstick.com/view/88527/fixing-quickbooks-error-4120-reinstalling-vs-repairing) saying:\
05-30 03:37:10.921: W/System.err(5408): android.database.CursorIndexOutOfBoundsException: Index -1 requested, with a size of 1 I have checked the database for the [records](https://www.mindstick.com/forum/34640/how-to-create-a-stored-procedure-for-display-all-records) manually and all the [required](https://www.mindstick.com/forum/160269/what-is-required-data-annotation-how-does-it-affect-model-validation) data is present. (Also if i just do a following query:\
"SELECT * FROM " + DB.Table.SUBJECT"for the same table and give the get the count for the cursor it gives me the existing number of records which is correct).\
Please Do Help...\
Thanks in advance.

## Replies

### Reply by AVADHESH PATEL

Hi Mark,\
Try this, maybe you made a mistake

```
final Cursor subject_cursor = db.rawQuery("SELECT * FROM " + DB.Table.SUBJECT + " WHERE uniqueSUB = '" + cs_cursor.getString(0) + "'", null);
```

\
Because you have only 1 row in your table, and your are trying to fetch 2nd row using cs_cursor.getString(1)\
Or try this code,\

```
public void getAllEvents() {    // Select All Query    String selectQuery = "SELECT  * FROM " + TABLE_EVENTS;    SQLiteDatabase db = this.getWritableDatabase();    Cursor cursor = db.rawQuery(selectQuery, null);    // looping through all rows and adding to list    if (cursor.moveToFirst()) {        do {            // Adding contact to list            MainActivity.Id.add(cursor.getString(0)); //it will store id to my array list "Id"        } while (cursor.moveToNext());    }}
```

\
I hope this code might be resolve your problem.


---

Original Source: https://www.mindstick.com/forum/943/cursorindexoutofboundsexception-for-table-and-records-existing

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
