I am getting an error Couldn't read row 0, col -1 from CursorWindow. Make sure the Cursor is initialized correctly before accessing data from it. I have tried everything, but nothing seems to work
Variables:
private static final String COLUMN_SERVICE_DETAILS = " service_details";
private static final String COLUMN_SERVICE_TIME = " service_time";
private static final String COLUMN_SERVICE_COST = " service_cost";
private static final String TABLE_DETAILS = "details";
Table creation
query = "CREATE TABLE " +TABLE_DETAILS+"("
+COLUMN_ID+ " INTEGER PRIMARY KEY AUTOINCREMENT, "
+COLUMN_SERVICE_TIME+ " TEXT, "
+COLUMN_SERVICE_DETAILS+ " TEXT, "
+COLUMN_SERVICE_COST+ " TEXT " +
");";
sqLiteDatabase.execSQL(query);
After debugging my app it stopped on this method getUserDetails
public UserDetails getUserDetails(){
UserDetails ud = new UserDetails();
String selectQuery = "select * from " + TABLE_DETAILS + " where 1;";
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.rawQuery(selectQuery, null);
// Move to first row
cursor.moveToFirst();
while (!cursor.isAfterLast()) {
ud.set_service_details(cursor.getString(cursor.getColumnIndex(COLUMN_SERVICE_DETAILS)));
ud.set_service_time(cursor.getString(cursor.getColumnIndex(COLUMN_SERVICE_TIME)));
ud.set_service_cost(cursor.getString(cursor.getColumnIndex(COLUMN_SERVICE_COST)));
cursor.moveToNext();
}
cursor.close();
db.close();
return ud;
}
Error log:
03-17 17:27:03.553 14627-14627/com.automobilecare.automobilecare E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.automobilecare.automobilecare, PID: 14627
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.automobilecare.automobilecare/com.automobilecare.automobilecare.userArea.UserAreaActivity}: java.lang.IllegalStateException: Couldn't read row 0, col -1 from CursorWindow. Make sure the Cursor is initialized correctly before accessing data from it.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2584)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2666)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.Activitat android.os.Handler.dispatchMessage(Handler.java:111)
at android.os.Looper.loop(Looper.java:207)
at android.app.ActivityThread.main(ActivityThread.java:5769)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:679)
at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:102)
Caused by: java.lang.IllegalStateException: Couldn't read row 0, col -1 from CursorWindow. Make sure the Cursor is initialized correctly before accessing data from it.
at android.database.CursorWindow.nativeGetString(Native Method)
at android.database.CursorWindow.getString(CursorWindow.java:438)
at android.database.AbstractWindowedCursor.getString(AbstractWindowedCursor.java:66)
at com.automobilecare.automobilecare.internalDBConnectivity.DBHandler.getUserDetails(DBHandler.java:240)
at com.automobilecare.automobilecare.userArea.UserAreaActivity.onCreate(UserAreaActivity.java:85)
at android.app.Activity.performCreate(Activity.java:6583)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1114)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2531)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2666)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1493)
at android.os.Handler.dispatchMessage(Handler.java:111)
at android.os.Looper.loop(Looper.java:207)
at android.app.ActivityThread.main(ActivityThread.java:5769)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:679)
at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:102)
Thank you for your help