java.lang.IllegalStateException: Couldn't read row 0, col 0 from CursorWindow


I need to fetch all data from a table,I used the following code to do the same in sqlite dbhelper class:

public Cursor getData() {
        SQLiteDatabase db = this.getWritableDatabase();
        Cursor res = db.rawQuery("select * from " + PRODUCT_DETAILS_TABLE, null);
        return res;

Now i'm fetching data using curser in my activity in the following way:

  public HashMap<String, ArrayList<CartModal>> getDatas() {

            map = new HashMap<String, ArrayList<CartModal>>();
            stored_data = new ArrayList<CartModal>();
            Cursor cartdb = dbHelper.getData();
            if (cartdb != null && cartdb.getCount() > 0) {
                if (cartdb.moveToFirst()) {
                    do {
                        String mloggedinuser = cartdb.getString(0);
                        String mname = cartdb.getString(1);
                        String email = cartdb.getString(2);
                        String mobile = cartdb.getString(3);
                        String about = cartdb.getString(4);
                        String pid = cartdb.getString(5);
                        String refnum = cartdb.getString(6);
                        String size = cartdb.getString(7);
                        String weight = cartdb.getString(8);
                        String price = cartdb.getString(9);
                        String catid = cartdb.getString(10);
                        String image = cartdb.getString(11);

                        CartModal cartarray = new CartModal(mloggedinuser, mname, email, mobile, about, pid, refnum, size, weight, price, catid, image);
                        keys = mname;
                        map.put(mname, stored_data);
                    } while (cartdb.moveToPosition(stored_data.size()));
            return map;

When i run the above program i'm getting error as follows:

E/AndroidRuntime: FATAL EXCEPTION: main
                  Process:, PID: 2434
                  java.lang.IllegalStateException: Couldn't read row 0, col 0 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(
                      at android.database.AbstractWindowedCursor.getString(
                      at android.os.Handler.handleCallback(
                      at android.os.Handler.dispatchMessage(
                      at android.os.Looper.loop(
                      at java.lang.reflect.Method.invoke(Native Method)

I've gone through many solutions in stackoverflow (android java.lang.IllegalStateException: Couldn't read row 0, col 0 from CursorWindow ),but none helped me to solve this issue. Please suggest me a solution.

Show source
| java   | android   | sqlite   | illegalstateexception   2017-01-07 09:01 1 Answers

Answers to java.lang.IllegalStateException: Couldn&#39;t read row 0, col 0 from CursorWindow ( 1 )

  1. 2017-01-07 12:01

    I was doing everything right.but the problem was,i was saving an image in db as base64 ecoded string.while fetching that data it shows illegal exception.when i removed that image it works pefectly. If anyone know how to save base64 encoded image as string in sqlite,please reply below.


Leave a reply to - java.lang.IllegalStateException: Couldn't read row 0, col 0 from CursorWindow

◀ Go back