android - 从 roomdb 表中获取所有消息时出现 IllegalStateException
问题描述
应用程序在后台任务中从数据库读取所有消息并且用户同时执行删除操作时有时会崩溃。
堆栈跟踪:
java.lang.IllegalStateException:无法从 CursorWindow 读取第 1426 行第 0 列。确保在从光标访问数据之前正确初始化光标。在
android.database.CursorWindow.nativeGetLong(Native Method) at android.database.CursorWindow.getLong(CursorWindow.java:542) at android.database.AbstractWindowedCursor.getLong(AbstractWindowedCursor.java:77) at com.android.smslib.db.dao.MessageDao_Impl$19.call(MessageDao_Impl.java:1044) at com.android.smslib.db.dao.MessageDao_Impl$19.call(MessageDao_Impl.java:1009) at androidx.room.CoroutinesRoom$Companion$execute$2.invokeSuspend(CoroutinesRoom.kt:54) at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33) at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) at
数据库查询:
@Query("SELECT * FROM message")
suspend fun getAllMessages(): List<Message>?
解决方案
推荐阅读
- python - Windows 中的设置命令不适用于 django SECRET_KEY | django.core.exceptions.ImproperlyConfigured:设置 SECRET_KEY 环境变量
- react-native - 使用 Reanimated 更改 Y 轴上的文本位置
- python - Django rest 删除请求错误“'file' 属性没有与之关联的文件。”
- datetime - 为日期时间字段设置默认时间 odoo 11
- java - 初始化并填充 Maps Maps
- wordpress - 使用 WordPress add_rewrite_rule() 更改帖子 URL
- php - 在windows中哪里可以找到vs代码目录/var/www/html/
- html - 根据类数更改css
- unity3d - 使用刚体速度进行 Unity 2D 跳跃感觉不好
- security - 保护从公共计算机到服务器的用户 ID 传输