安卓java.lang.IllegalStateException:无法从CursorWindow读取行0,列0 [英] android java.lang.IllegalStateException: Couldn't read row 0, col 0 from CursorWindow

查看:4791
本文介绍了安卓java.lang.IllegalStateException:无法从CursorWindow读取行0,列0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发了在外地FILE_CONTENT下载一些文件,并保存其文本数据库的应用程序。文件大小可以改变一些KB的10 MB。该应用程序适用于同时节省各种规模。长FILE_CONTENT记录使用SELECT语句时,会出现问题。它给

  

java.lang.IllegalStateException:无法从CursorWindow读取行0,列0

取这样的行时。有没有现场内容大小的限制么?如果是这样,那么为什么它让我们保存和提供错误而检索? 这是我的code剪断了获取行:

 公共字符串getFileContent(MyFile的GC){
        如果(!isDBOpen()){
            打开();
        }
        尝试 {
            字符串mQuery =SELECT * FROM+ DBOpenHelper.TABLE_SAVED_FILES +WHERE+ DBOpenHelper.COLUMN_ID +=+ gc.id;
            光标mCursor = database.rawQuery(mQuery,NULL);
            如果(mCursor.getCount()&其中; = 0){
                返回null;
            }
            如果(mCursor.moveToFirst()){
                返回getCursorRowContent(mCursor);
            }
        }赶上(例外五){
            e.getMessage();
        }
        返回null;
    }

    私人字符串getCursorRowContent(光标mCursor)抛出异常{
        返回mCursor.getString(mCursor.getColumnIndex(DBOpenHelper.COLUMN_FILE_CONTENT));
    }
 

任何想法是怎么回事?我已在2至3个设备进行了测试。

logcat的输出:

  01-29 13:41:56.520:W / CursorWindow(4121):窗口是全:请求的分配5140987字节的可用空间2096617字节,窗口大小2097152字节
01-29 13:41:56.520:E / CursorWindow(4121):无法从CursorWindow有0行,9列读行0,列0。

01-29 13:43:30.932:W / System.err的(4121):java.lang.IllegalStateException:无法从CursorWindow读取行0,列0。确保光标从它访问数据之前,正确初始化。
01-29 13:43:30.932:W / System.err的(4121):在android.database.CursorWindow.nativeGetLong(本机方法)
01-29 13:43:30.932:W / System.err的(4121):在android.database.CursorWindow.getLong(CursorWindow.java:507)
01-29 13:43:30.932:W / System.err的(4121):在android.database.AbstractWindowedCursor.getLong(AbstractWindowedCursor.java:75)
01-29 13:43:30.936:W / System.err的(4121):在android.database.AbstractCursor.moveToPosition(AbstractCursor.java:220)
01-29 13:43:30.936:W / System.err的(4121):在android.database.AbstractCursor.moveToNext(AbstractCursor.java:245)
01-29 13:43:30.940:W / System.err的(4121):在com.nxb.cachehead.bl.PocketQueryDataSource.getGeoCacheContent(PocketQueryDataSource.java:97)01-29 13:43:30.940:W /系统。犯错(4121):在com.nxb.cachehead.bl.GPXFileCopyAsyncTask.doInBackground(GPXFileCopyAsyncTask.java:27)
01-29 13:43:30.940:W / System.err的(4121):在com.nxb.cachehead.bl.GPXFileCopyAsyncTask.doInBackground(GPXFileCopyAsyncTask.java:1)
01-29 13:43:30.940:W / System.err的(4121):在android.os.AsyncTask $ 2.call(AsyncTask.java:287)
01-29 13:43:30.944:W / System.err的(4121):在java.util.concurrent.FutureTask.run(FutureTask.java:234)
01-29 13:43:30.944:W / System.err的(4121):在android.os.AsyncTask $ SerialExecutor $ 1.运行(AsyncTask.java:230)
01-29 13:43:30.948:W / System.err的(4121):在java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
01-29 13:43:30.948:W / System.err的(4121):在java.util.concurrent.ThreadPoolExecutor中的$ Worker.run(ThreadPoolExecutor.java:573)
01-29 13:43:30.948:W / System.err的(4121):在java.lang.Thread.run(Thread.java:856)
 

解决方案
  

01-29 13:41:56.520:W / CursorWindow(4121):窗口是全:请求的分配5140987字节的可用空间2096617字节,窗口大小2097152字节

Android的SQLite的返回具有2MB的最大大小所指定的<一个在光标窗口行href="https://github.com/android/platform_frameworks_base/blob/master/core/res/res/values/config.xml#L942"><$c$c>config_cursorWindowSize.如果你的行超过此限制时,您会收到此错误。

在SQLite数据库存储大量的数据是不是一个好主意呢。在文件系统中的数据库中存储的文件和路径。

I am developing an application which download some files and save their text in file_content field to database. The file sizes can vary from some KBs to 10 MB. The app works for all sizes while saving. The problem occurs when using select statement on long file_content records. It gives

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

when fetching such rows. Are there any limits on field content size? If so, then why it is letting us to save and giving error while retrieving? Here is my code snipped that fetches row:

public String getFileContent(MyFile gc) {
        if(!isDBOpen()) {
            open();
        }
        try {
            String mQuery = "SELECT * FROM " + DBOpenHelper.TABLE_SAVED_FILES + " WHERE " + DBOpenHelper.COLUMN_ID + " = " + gc.id;
            Cursor mCursor = database.rawQuery(mQuery, null);
            if(mCursor.getCount() <= 0) {
                return null;
            }
            if(mCursor.moveToFirst()) {
                return getCursorRowContent(mCursor);
            }
        } catch (Exception e) {
            e.getMessage();
        }
        return null;
    }

    private String getCursorRowContent(Cursor mCursor) throws Exception {
        return mCursor.getString(mCursor.getColumnIndex(DBOpenHelper.COLUMN_FILE_CONTENT));
    }

Any idea what is going on? I have tested it on 2 to 3 devices.

Logcat output:

01-29 13:41:56.520: W/CursorWindow(4121): Window is full: requested allocation 5140987 bytes, free space 2096617 bytes, window size 2097152 bytes
01-29 13:41:56.520: E/CursorWindow(4121): Failed to read row 0, column 0 from a CursorWindow which has 0 rows, 9 columns.

01-29 13:43:30.932: W/System.err(4121): java.lang.IllegalStateException: Couldn't read row 0, col 0 from CursorWindow.  Make sure the Cursor is initialized correctly before accessing data from it. 
01-29 13:43:30.932: W/System.err(4121):     at android.database.CursorWindow.nativeGetLong(Native Method) 
01-29 13:43:30.932: W/System.err(4121):     at android.database.CursorWindow.getLong(CursorWindow.java:507) 
01-29 13:43:30.932: W/System.err(4121):     at android.database.AbstractWindowedCursor.getLong(AbstractWindowedCursor.java:75) 
01-29 13:43:30.936: W/System.err(4121):     at android.database.AbstractCursor.moveToPosition(AbstractCursor.java:220) 
01-29 13:43:30.936: W/System.err(4121):     at android.database.AbstractCursor.moveToNext(AbstractCursor.java:245) 
01-29 13:43:30.940: W/System.err(4121):     at com.nxb.cachehead.bl.PocketQueryDataSource.getGeoCacheContent(PocketQueryDataSource.java:97) 01-29 13:43:30.940: W/System.err(4121):     at com.nxb.cachehead.bl.GPXFileCopyAsyncTask.doInBackground(GPXFileCopyAsyncTask.java:27) 
01-29 13:43:30.940: W/System.err(4121):     at com.nxb.cachehead.bl.GPXFileCopyAsyncTask.doInBackground(GPXFileCopyAsyncTask.java:1) 
01-29 13:43:30.940: W/System.err(4121):     at android.os.AsyncTask$2.call(AsyncTask.java:287) 
01-29 13:43:30.944: W/System.err(4121):     at java.util.concurrent.FutureTask.run(FutureTask.java:234) 
01-29 13:43:30.944: W/System.err(4121):     at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230) 
01-29 13:43:30.948: W/System.err(4121):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080) 
01-29 13:43:30.948: W/System.err(4121):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573) 
01-29 13:43:30.948: W/System.err(4121):     at java.lang.Thread.run(Thread.java:856)

解决方案

01-29 13:41:56.520: W/CursorWindow(4121): Window is full: requested allocation 5140987 bytes, free space 2096617 bytes, window size 2097152 bytes

Android SQLite returns rows in cursor windows that have the maximum size of 2MB as specified by config_cursorWindowSize. If your row exceeds this limit, you'll get this error.

Storing large data in sqlite database is not a good idea anyway. Store files in filesystem and paths in database.

这篇关于安卓java.lang.IllegalStateException:无法从CursorWindow读取行0,列0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆