首页 > 解决方案 > 从 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>?

标签: androidkotlinandroid-roomillegalstateexception

解决方案


推荐阅读