android java.lang.IllegalStateException: 无法从 CursorWindow 读取第 0 行、第 0 列
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21432556/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
android java.lang.IllegalStateException: Couldn't read row 0, col 0 from CursorWindow
提问by Khawar Raza
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
我正在开发一个应用程序,它下载一些文件并将它们在 file_content 字段中的文本保存到数据库中。文件大小可以从一些 KB 到 10 MB 不等。该应用程序在保存时适用于所有尺寸。在长 file_content 记录上使用 select 语句时会出现问题。它给
java.lang.IllegalStateException: Couldn't read row 0, col 0 from CursorWindow
java.lang.IllegalStateException:无法从 CursorWindow 读取第 0 行、第 0 列
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.
知道发生了什么吗?我已经在 2 到 3 台设备上对其进行了测试。
Logcat output:
Logcat 输出:
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.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.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)
回答by laalto
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: W/CursorWindow(4121): 窗口已满:请求分配 5140987 字节,可用空间 2096617 字节,窗口大小 2097152 字节
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.
Android SQLite 返回光标窗口中最大大小为 2MB 的行,由config_cursorWindowSize
. 如果您的行超过此限制,您将收到此错误。
Storing large data in sqlite database is not a good idea anyway. Store files in filesystem and paths in database.
无论如何,将大量数据存储在 sqlite 数据库中并不是一个好主意。将文件存储在文件系统中,将路径存储在数据库中。
回答by alibabaei12
In case you want to save images as bytes, Another way to do this is, while compressing the bitmap, set the quality to 0.
如果您想将图像保存为字节,另一种方法是在压缩位图时,将质量设置为 0。