微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

java.lang.IllegalStateException:无法从CursorWindow读取第0行col 0

我需要从表中获取所有数据,我使用以下代码sqlite dbhelper类中执行相同的操作:

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

现在我用以下方式在我的活动中使用光标获取数据:

  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);
                        stored_data.add(cartarray);
                        keys = mname;
                        map.put(mname, stored_data);
                    } while (cartdb.movetoPosition(stored_data.size()));
                    cartdb.close();
                }
            }
            return map;
        }

当我运行上述程序时,我收到如下错误

E/AndroidRuntime: FATAL EXCEPTION: main
                  Process: sdetech.io.brouchuretabproject, 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(CursorWindow.java:438)
                      at android.database.AbstractwindowedCursor.getString(AbstractwindowedCursor.java:51)
                      at sdetech.io.brouchuretabproject.Fragments.Cart.getDatas(Cart.java:58)
                      at sdetech.io.brouchuretabproject.Fragments.Cart.onCreateView(Cart.java:42)
                      at android.support.v4.app.Fragment.performCreateView(Fragment.java:2087)
                      at android.support.v4.app.FragmentManagerImpl.movetoState(FragmentManager.java:1113)
                      at android.support.v4.app.FragmentManagerImpl.movetoState(FragmentManager.java:1295)
                      at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:801)
                      at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1682)
                      at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:541)
                      at android.os.Handler.handleCallback(Handler.java:739)
                      at android.os.Handler.dispatchMessage(Handler.java:95)
                      at android.os.Looper.loop(Looper.java:148)
                      at android.app.ActivityThread.main(ActivityThread.java:5417)
                      at java.lang.reflect.Method.invoke(Native Method)
                      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

我在stackoverflow(android java.lang.IllegalStateException: Couldn’t read row 0, col 0 from CursorWindow)中经历了很多解决方案,但没有人帮助我解决这个问题.
请建议我一个解决方案.

解决方法:

我正在做的一切正确.但问题是,我正在db中保存一个图像作为base64 ecoded string.虽然获取该数据它显示非法异常.当我删除该图像时,它完美地工作.
如果有人知道如何在sqlite中将base64编码的图像保存为字符串,请在下面回复.

谢谢

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐