我正在开发一个应用程序,它下载一些文件并将它们的文本保存在file_content字段中。文件大小可能从几KB到10 MB不等。该应用程序适用于所有尺寸,同时保存。在long file_content记录上使用select语句时会发生此问题。它给出了
java.lang.IllegalStateException:无法读取CursorWindow中的第0行,第0列
获取此类行时。字段内容大小有限制吗?如果是这样,那么为什么它让我们在检索时保存并给出错误? 这是我的代码剪切,提取行:
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));
}
知道发生了什么事吗?我已经在2到3台设备上进行了测试。
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$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)
答案 0 :(得分:84)
01-29 13:41:56.520:W / CursorWindow(4121):窗口已满:请求分配5140987字节,可用空间2096617字节,窗口大小2097152字节
Android SQLite返回光标窗口中的行,config_cursorWindowSize
指定的最大大小为2MB。如果您的行超出此限制,您将收到此错误。
无论如何,在sqlite数据库中存储大数据并不是一个好主意。将文件存储在文件系统和数据库中的路径中。
答案 1 :(得分:0)
如果要将图像保存为字节,另一种方法是在压缩位图时将质量设置为0。