das*_*ima 5 android android-cursor android-room android-livedata
我们最近在使用 Android 的 Room 数据库时遇到了一些问题。
崩溃只发生在某些用户身上,但我无法在我的测试设备或模拟器上重现它。(这有时也会发生在 Firebase 测试设备上)
有一些例外似乎都是相关的。
所有这些异常都发生在我们由 Room 生成的 Dao 的不同行中。
(无论是查询、插入、更新还是删除)。
CursorWindowAllocationException: Cursor window allocation of 2048 kb failed.
IllegalStateException: attempt to re-open an already-closed object: SQLiteDatabase: ‘/whatever/database’
SQLiteDiskIOException: disk I/O error (code 266)
SQLiteDiskIOException: disk I/O error (code 778)
SQLiteDatabaseCorruptException: file is encrypted or is not a database (code 26)
SQLiteException: Failed to change locale for db ‘/whatever/database' to 'fr_FR'.
Run Code Online (Sandbox Code Playgroud)
我试过的:
这些方法都没有帮助,错误仍然存在。
该LiveData的查询是唯一一个这是不卸载默认的数据库执行者,因为我无法找到一个方法来做到这一点。我怀疑这可能是问题所在,但我不完全确定。
这是 LiveData 查询
@Query("SELECT * FROM alarms WHERE deleted =0 ORDER BY isActive DESC, hourOfDay, minuteOfHour")
LiveData<List<Alarm>> getLiveAlarmList();
Run Code Online (Sandbox Code Playgroud)
异常示例:
Fatal Exception: android.database.CursorWindowAllocationException: Cursor window allocation of 2048 kb failed.
at android.database.CursorWindow.(CursorWindow.java:108)
at android.database.AbstractWindowedCursor.clearOrCreateWindow(AbstractWindowedCursor.java:198)
at android.database.sqlite.SQLiteCursor.clearOrCreateWindow(SQLiteCursor.java:300)
at android.database.sqlite.SQLiteCursor.fillWindow(SQLiteCursor.java:138)
at android.database.sqlite.SQLiteCursor.getCount(SQLiteCursor.java:132)
at android.database.AbstractCursor.moveToPosition(AbstractCursor.java:219)
at android.database.AbstractCursor.moveToNext(AbstractCursor.java:268)
at android.arch.persistence.room.InvalidationTracker$1.checkUpdatedTable(SourceFile:358)
at android.arch.persistence.room.InvalidationTracker$1.run(SourceFile:329)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
at java.lang.Thread.run(Thread.java:762)
Run Code Online (Sandbox Code Playgroud)
这个似乎源自 Room 的 LiveData InvalidationTracker 类。
Fatal Exception: android.database.CursorWindowAllocationException: Cursor window allocation of 2048 kb failed. # Open Cursors=1 (# cursors opened by this proc=1)
at android.database.CursorWindow.(CursorWindow.java:108)
at android.database.AbstractWindowedCursor.clearOrCreateWindow(AbstractWindowedCursor.java:225)
at android.database.sqlite.SQLiteCursor.fillWindow(SQLiteCursor.java:149)
at android.database.sqlite.SQLiteCursor.getCount(SQLiteCursor.java:143)
at com.sofaking.moonworshipper.database.room.AlarmDao_Impl.getAllAlarms(SourceFile:458)
at com.sofaking.moonworshipper.database.AlarmHelper.getAllAlarms(SourceFile:29)
at com.sofaking.moonworshipper.registration.DefaultAlarmRegistrationImpl.onCancelPendingAlarms(SourceFile:36)
at com.sofaking.moonworshipper.registration.BaseAlarmRegistrationImpl$start$runnable$1.run(SourceFile:26)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
at java.lang.Thread.run(Thread.java:761)
Run Code Online (Sandbox Code Playgroud)
虽然这个来自查询“所有警报”的服务。请注意,'AlarmDao_Impl.getAllAlarms' 是由 Room 生成的,并且在完成后确实关闭了光标。
Fatal Exception: android.database.sqlite.SQLiteDiskIOException: disk I/O error (code 266)
at android.database.sqlite.SQLiteConnection.nativeExecuteForCursorWindow(SQLiteConnection.java)
at android.database.sqlite.SQLiteConnection.executeForCursorWindow(SQLiteConnection.java:1015)
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:147)
at android.database.sqlite.SQLiteCursor.getCount(SQLiteCursor.java:136)
at android.database.AbstractCursor.moveToPosition(AbstractCursor.java:197)
at android.database.AbstractCursor.moveToFirst(AbstractCursor.java:237)
at android.arch.persistence.room.RoomOpenHelper.checkIdentity(SourceFile:127)
at android.arch.persistence.room.RoomOpenHelper.onOpen(SourceFile:115)
at android.arch.persistence.db.framework.FrameworkSQLiteOpenHelper$OpenHelper.onOpen(SourceFile:151)
at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:266)
at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:163)
at android.arch.persistence.db.framework.FrameworkSQLiteOpenHelper$OpenHelper.getWritableSupportDatabase(SourceFile:96)
at android.arch.persistence.db.framework.FrameworkSQLiteOpenHelper.getWritableDatabase(SourceFile:54)
at android.arch.persistence.room.RoomDatabase.query(SourceFile:233)
at com.sofaking.moonworshipper.database.room.AlarmDao_Impl$4.compute(SourceFile:555)
at com.sofaking.moonworshipper.database.room.AlarmDao_Impl$4.compute(SourceFile:541)
at android.arch.lifecycle.ComputableLiveData$2.run(SourceFile:100)
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)
Run Code Online (Sandbox Code Playgroud)
另一个 LiveData 查询崩溃。
Fatal Exception: android.database.sqlite.SQLiteDiskIOException: disk I/O error (code 778)
at android.database.sqlite.SQLiteConnection.nativeExecute(SQLiteConnection.java)
at android.database.sqlite.SQLiteConnection.execute(SQLiteConnection.java:561)
at android.database.sqlite.SQLiteSession.endTransactionUnchecked(SQLiteSession.java:437)
at android.database.sqlite.SQLiteSession.endTransaction(SQLiteSession.java:401)
at android.database.sqlite.SQLiteDatabase.endTransaction(SQLiteDatabase.java:528)
at android.arch.persistence.db.framework.FrameworkSQLiteDatabase.endTransaction(SourceFile:90)
at android.arch.persistence.room.RoomDatabase.endTransaction(SourceFile:261)
at com.sofaking.moonworshipper.database.room.AlarmDao_Impl.update(SourceFile:188)
at com.sofaking.moonworshipper.registration.DefaultAlarmRegistrationImpl.onCalculateAlarms(SourceFile:58)
at com.sofaking.moonworshipper.registration.BaseAlarmRegistrationImpl$start$runnable$1.run(SourceFile:37)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
at java.lang.Thread.run(Thread.java:764)
Run Code Online (Sandbox Code Playgroud)
这来自更新对象实例(也由 Room 处理)
Fatal Exception: android.database.sqlite.SQLiteDatabaseCorruptException: file is encrypted or is not a database (code 26)
at android.database.sqlite.SQLiteConnection.nativeExecuteForCursorWindow(SQLiteConnection.java)
at android.database.sqlite.SQLiteConnection.executeForCursorWindow(SQLiteConnection.java:845)
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:143)
at android.database.sqlite.SQLiteCursor.getCount(SQLiteCursor.java:132)
at android.database.AbstractCursor.moveToPosition(AbstractCursor.java:219)
at android.database.AbstractCursor.moveToFirst(AbstractCursor.java:258)
at android.arch.persistence.room.RoomOpenHelper.hasRoomMasterTable(SourceFile:155)
at android.arch.persistence.room.RoomOpenHelper.checkIdentity(SourceFile:123)
at android.arch.persistence.room.RoomOpenHelper.onOpen(SourceFile:115)
at android.arch.persistence.db.framework.FrameworkSQLiteOpenHelper$OpenHelper.onOpen(SourceFile:151)
at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:266)
at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:163)
at android.arch.persistence.db.framework.FrameworkSQLiteOpenHelper$OpenHelper.getWritableSupportDatabase(SourceFile:96)
at android.arch.persistence.db.framework.FrameworkSQLiteOpenHelper.getWritableDatabase(SourceFile:54)
at android.arch.persistence.room.RoomDatabase.query(SourceFile:233)
at com.sofaking.moonworshipper.database.room.AlarmDao_Impl$4.compute(SourceFile:321)
at com.sofaking.moonworshipper.database.room.AlarmDao_Impl$4.compute(SourceFile:307)
at android.arch.lifecycle.ComputableLiveData$2.run(SourceFile:100)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
at java.lang.Thread.run(Thread.java:761)
Run Code Online (Sandbox Code Playgroud)
同样,似乎来自 LiveData 的 AlarmDao_Impl$4.compute() 方法
Fatal Exception: android.database.sqlite.SQLiteException: Failed to change locale for db '/data/user_de/0/com.sofaking.moonworshipper/databases/alarm-database' to 'fr_FR'.
at android.database.sqlite.SQLiteConnection.setLocaleFromConfiguration(SQLiteConnection.java:402)
at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:223)
at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:198)
at android.database.sqlite.SQLiteConnectionPool.openConnectionLocked(SQLiteConnectionPool.java:463)
at android.database.sqlite.SQLiteConnectionPool.tryAcquireNonPrimaryConnectionLocked(SQLiteConnectionPool.java:899)
at android.database.sqlite.SQLiteConnectionPool.waitForConnection(SQLiteConnectionPool.java:609)
at android.database.sqlite.SQLiteConnectionPool.acquireConnection(SQLiteConnectionPool.java:348)
at android.database.sqlite.SQLiteSession.acquireConnection(SQLiteSession.java:894)
at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:586)
at android.database.sqlite.SQLiteProgram.(SQLiteProgram.java:58)
at android.database.sqlite.SQLiteQuery.(SQLiteQuery.java:37)
at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:44)
at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1353)
at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1328)
at android.arch.persistence.db.framework.FrameworkSQLiteDatabase.query(SourceFile:161)
at android.arch.persistence.room.RoomDatabase.query(SourceFile:233)
at com.sofaking.moonworshipper.database.room.AlarmDao_Impl.getAllAlarms(SourceFile:438)
at com.sofaking.moonworshipper.database.AlarmHelper.getAllAlarms(SourceFile:29)
at com.sofaking.moonworshipper.registration.DefaultAlarmRegistrationImpl.onCancelPendingAlarms(SourceFile:36)
at com.sofaking.moonworshipper.registration.BaseAlarmRegistrationImpl$start$runnable$1.run(SourceFile:26)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
at java.lang.Thread.run(Thread.java:761)
Run Code Online (Sandbox Code Playgroud)
与第二个 CursorWindowAllocationException 相同的区域,但有不同的崩溃
最后,错误与数据库本身无关。我有一些图像资源未调整为 MDPI、HDPI 或 XHDPI。它们仅以 XXHDPI 形式提供。
引用另一个线程的答案: /sf/answers/1810290471/
如果你查一下它的来源,CursorWindowAllocationException它是这样写的:
当无法分配 CursorWindow 时会引发此异常,很可能是由于内存不可用。
显然,由于图像占用了应用程序的大量堆内存,因此光标无法自行分配。
现在我没有发生这些崩溃了。
| 归档时间: |
|
| 查看次数: |
5458 次 |
| 最近记录: |