sqlite curser.getcount 不为0,但是取不出数据

Simmons_Song 2016-12-29 09:04:56
rt android
报错如下
Failed to read row 0, column 1 from a CursorWindow which has 0 rows, 2 columns.
12-29 08:51:44.733 12559-12649/com.ssl.hitpatrol E/PatrolDAO: 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.ssl.hitpatrol.dao.PatrolDAO.getPhotoStrings(PatrolDAO.java:783)
at com.ssl.hitpatrol.activity.MainActivity$20$1.doInBackground(MainActivity.java:807)
at com.ssl.hitpatrol.activity.MainActivity$20$1.doInBackground(MainActivity.java:762)
at android.os.AsyncTask$2.call(AsyncTask.java:292)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:818)
...全文
418 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
Simmons_Song 2016-12-29
  • 打赏
  • 举报
回复
没用,直接用cursor的的query
LongRui888 2016-12-29
  • 打赏
  • 举报
回复
最好是下个断点跟踪一下程序,你是调用的orm库来操作数据库的把
致命的西瓜 2016-12-29
  • 打赏
  • 举报
回复
把你的sql打印出来看看
Simmons_Song 2016-12-29
  • 打赏
  • 举报
回复
SQLiteDatabase db = null;
        Cursor cursor = null;
        try {
            db = patrolDBHelper.getReadableDatabase();
            // 获取当前taskcode的base64编码的图片
//            cursor = db.rawQuery("select photoBase64Code from patrolphotos where taskCode=?", new String[]{taskCode});
            cursor = db.query(patrolDBHelper.TABLE_NAME_PHOTO, TABLE_NAME_PHOTO, "taskCode=?", new String[]{taskCode}, null, null, null);
            if (cursor.getCount() > 0) {
                ArrayList<String> images = new ArrayList<>(cursor.getCount());
                Log.e("图片的hang数222222222222222", cursor.getCount() + "");
                while (cursor.moveToNext()) {
                    images.add(cursor.getString(cursor.getColumnIndex("photoBase64Code")));
                }
                return images;
            }
        } catch (Exception e) {
            Log.e(TAG, "", e);
        } finally {
            if (cursor != null) {
                cursor.close();
            }
            if (db != null) {
                db.close();
            }
        }
        return null;
Simmons_Song 2016-12-29
  • 打赏
  • 举报
回复
打印的curser的长度:E/图片的hang数222222222222222: 4

2,209

社区成员

发帖
与我相关
我的任务
社区描述
其他数据库开发 其他数据库
社区管理员
  • 其他数据库社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧