I have a function to read data from db.but this always returns error..i dont have much knowledge in android..looking for some help
10-03 11:33:05.870: E/AndroidRuntime(1321): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.projects.myworldsafe/com.projects.myworldsafe.DeailedView}: android.database.CursorIndexOutOfBoundsException: Index 0 requested, with a size of 0
.
String getItemDetailsWp(String id){
System.out.print(id);
SQLiteDatabase db = this.getReadableDatabase();
String[] params=new String[]{id};
String selectQuery = "SELECT Content FROM " + TABLE_ITEMS +" WHERE "+ITEM_ID+"=?";
Cursor c=db.rawQuery(selectQuery,params);
c.moveToFirst();
int index= c.getCount();
int indexd= c.getColumnIndex(ITEM_CONTENT);
System.out.print("Count query"+indexd);
return c.getString(index);
}
use this:
it is what you actually want to get value of. you used
indexthere,which returns number of record in your cursor.also better practice is: