android – cursor not fetching records from database-ThrowExceptions

Exception or error:

I am unable to fetch records from sqlite database.
Here is my code below:

This function is defined in the database file:

public Cursor fetchRecordById(String id) {
     Cursor cursor = sqLiteDatabase.rawQuery("select * from " + STDTABLE + " where _id = "+id, null);
     return cursor;

I am calling this function in main activity in that way:

Cursor cursor = sqLite.fetchRecordById(getId);

I got no values by calling this line:

String data = cursor.getString(cursor.getColumnIndex("name"));

I want to get the values from the column.

But i got error

Make sure the Cursor is initialized correctly before accessing data
from it.

I tried cursor.moveToNext(); & cursor.moveToFirst(); but no use. Kindly help

How to solve:

Leave a Reply

Your email address will not be published. Required fields are marked *