Android SQLiteDiskIOException(代码 522 SQLITE_IOERR_SHORT_READ)

标签 android android-sqlite android-workmanager

我在 Android O 上使用 Room 数据库,不时遇到 SQLiteDisckIOException,我尝试解决问题,但堆栈没有告诉我失败点在哪里。有人可以给我一些提示或如何解决此类问题吗?这里的潜在问题是什么?我正在编写的应用程序会在位置更改时写入数据库,并且还有一些后台任务会在需要时定期更新数据库。

这是我看到的堆栈:

10-07 22:29:41.404 22214-22226/? E/DataBuffer: Internal data leak within a DataBuffer object detected!  Be sure to explicitly call release() on all DataBuffer extending objects when you are done with them. (internal object: com.google.android.gms.common.data.DataHolder@b0fef92)
10-07 22:29:41.405 22214-22226/? E/DataBuffer: Internal data leak within a DataBuffer object detected!  Be sure to explicitly call release() on all DataBuffer extending objects when you are done with them. (internal object: com.google.android.gms.common.data.DataHolder@db3ad63)
10-07 22:29:41.415 19847-19847/com.firsapp.testing E/Periodic: from PIM->onCreateOptionMenu
10-07 22:29:41.442 19847-21824/com.firsapp.testing E/SQLiteLog: (522) statement aborts at 7: [SELECT DISTINCT tag FROM worktag WHERE work_spec_id=?] disk I/O error
10-07 22:29:41.443 19847-21824/com.firsapp.testing E/SQLiteQuery: exception: disk I/O error (code 522 SQLITE_IOERR_SHORT_READ); query: SELECT DISTINCT tag FROM worktag WHERE work_spec_id=?
10-07 22:29:41.449 19847-21824/com.firsapp.testing E/AndroidRuntime: FATAL EXCEPTION: pool-6-thread-2
        Process: com.firsapp.testing, PID: 19847
        android.database.sqlite.SQLiteDiskIOException: disk I/O error (code 522 SQLITE_IOERR_SHORT_READ)
        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)
        at androidx.work.impl.model.WorkTagDao_Impl.getTagsForWorkSpecId(WorkTagDao_Impl.java:92)
        at androidx.work.impl.WorkerWrapper.run(WorkerWrapper.java:102)
        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)
10-07 22:29:41.579 890-890/? E/lowmemorykiller: Error writing /proc/19847/oom_score_adj; errno=22

最佳答案

来自 SQLite 文档 SQLITE_IOERR_SHORT_READ 指的是数据库无法从文件系统读取请求的字节数的情况。

https://www.sqlite.org/rescode.html#ioerr_short_read

您是否允许您的应用程序安装在外部存储目录中? https://developer.android.com/guide/topics/manifest/manifest-element.html#install

我的猜测是:

  • 设备上的文件系统有问题。
  • 该应用程序位于外部存储目录中,并且在用户使用您的应用程序时移除了 SD 卡,这导致 SQLite 抛出此异常。

关于Android SQLiteDiskIOException(代码 522 SQLITE_IOERR_SHORT_READ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52695123/

相关文章:

android - 从 BroadCast 接收器启动 Activity

mysql - 如果最后一条记录与之前的记录重复,则android-db查询获取最后一条记录或组中的第一条

android - ReActiveAndroid - 未找到引用的数据库信息

android - Workmanager 中唯一的 OneTimeWorkRequest

android - 如何使用 Android Worker 观察最后发出的 WorkManager getWorkInfoByIdLiveData

android - 如何在 Doze 模式下检测维护窗口将关闭事件?

Android 线程和服务优先级

android - 当我在 android 中按下返回时,为什么不退出应用程序?

android - PagerSlidingTabStrip - 在运行时添加新选项卡

java - 在sql查询中使用变量作为列名