Bik*_*ani 5 sqlite android android-database
我只在android 9中遇到异常,重新安装一切看起来不错之后,
例外:
android.database.sqlite.SQLiteBlobTooBigException: Row too big to fit into CursorWindow requiredPos=0, totalRows=1...
Run Code Online (Sandbox Code Playgroud)
码:
Cursor cursor = database.query(......);
if(cursor == null || cursor.getCount() < 0) { //Here is the error
Log.d("Error", "count : null");
return "";
}
Run Code Online (Sandbox Code Playgroud)
编辑:
java.lang.RuntimeException: An error occurred while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:354)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:383)
at java.util.concurrent.FutureTask.setException(FutureTask.java:252)
at java.util.concurrent.FutureTask.run(FutureTask.java:271)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:764)
Caused by: android.database.sqlite.SQLiteBlobTooBigException: Row too big to fit into CursorWindow requiredPos=0, totalRows=1
at android.database.sqlite.SQLiteConnection.nativeExecuteForCursorWindow(Native Method)
at android.database.sqlite.SQLiteConnection.executeForCursorWindow(SQLiteConnection.java:859)
at android.database.sqlite.SQLiteSession.executeForCursorWindow(SQLiteSession.java:836)
at android.database.sqlite.SQLiteQuery.fillWindow(SQLiteQuery.java:62)
at android.database.sqlite.SQLiteCursor.fillWindow(SQLiteCursor.java:149)
at android.database.sqlite.SQLiteCursor.getCount(SQLiteCursor.java:137)
Run Code Online (Sandbox Code Playgroud)
在此先感谢大家
小智 23
这对我有用,你必须把它放在你的主要活动中。
try {
Field field = CursorWindow.class.getDeclaredField("sCursorWindowSize");
field.setAccessible(true);
field.set(null, 100 * 1024 * 1024); //the 100MB is the new size
} catch (Exception e) {
e.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)
尝试 API 28 之上的这个新构造函数。也许您应该为 CursorWindow 设置一个有限的 windowSizeBytes 并尝试捕获异常。
\n\n\n\n public void testRowTooBig() {\n mDatabase.execSQL("CREATE TABLE Tst (Txt BLOB NOT NULL);");\n byte[] testArr = new byte[10000];\n Arrays.fill(testArr, (byte) 1);\n for (int i = 0; i < 10; i++) {\n mDatabase.execSQL("INSERT INTO Tst VALUES (?)", new Object[]{testArr});\n }\n // Now reduce window size, so that no rows can fit\n Cursor cursor = mDatabase.rawQuery("SELECT * FROM TST", null);\n CursorWindow cw = new CursorWindow("test", 5000);\n AbstractWindowedCursor ac = (AbstractWindowedCursor) cursor;\n ac.setWindow(cw);\n try {\n ac.moveToNext();\n fail("Exception is expected when row exceeds CursorWindow size");\n } catch (SQLiteBlobTooBigException expected) {\n }\n }\nRun Code Online (Sandbox Code Playgroud)\n\n其他的:
\n\n\n\n\n由于本文最初发布,我们\xe2\x80\x99 在 Android P 开发者预览版中添加了新的 API,以改进上述行为。该平台现在允许应用禁用窗口启发式的 \xe2\x85\x93 并\n 配置 CursorWindow 大小。
\n
参考链接:\n https://medium.com/androiddevelopers/large-database-queries-on-android-cb043ae626e8
\n