【发布时间】:2020-08-12 16:26:53
【问题描述】:
在运行查询以从房间数据库返回一些数据时,我在 API 23 物理设备上遇到了这个崩溃。
LOGCAT
E/AndroidRuntime: FATAL EXCEPTION: arch_disk_io_2
java.lang.RuntimeException: Exception while computing database live data.
at androidx.room.RoomTrackingLiveData$1.run(RoomTrackingLiveData.java:92)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
at java.lang.Thread.run(Thread.java:818)
Caused by: java.lang.IllegalArgumentException: column '`allOrNothing`' does not exist
at android.database.AbstractCursor.getColumnIndexOrThrow(AbstractCursor.java:333)
at androidx.room.util.CursorUtil.getColumnIndexOrThrow(CursorUtil.java:108)
at com.example.persistence.dao.DaoPieChart_Impl$2.call(DaoPieChart_Impl.java:169)
at com.example.persistence.dao.DaoPieChart_Impl$2.call(DaoPieChart_Impl.java:164)
at androidx.room.RoomTrackingLiveData$1.run(RoomTrackingLiveData.java:90)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
at java.lang.Thread.run(Thread.java:818)
我查看了表格和模型,但看不到问题所在。列名明显存在。
表格
@Entity (tableName = "tableDistortedThinking")
public class TableDistortedThinking {
@PrimaryKey(autoGenerate = true)
private long pkDistortedThinking;
@ColumnInfo(name = "reframingId")
private long fkReframingId;
@ColumnInfo(name = "userId")
private long fkUserId;
@ColumnInfo(name = "allOrNothing")
private Integer allOrNothing;
型号
public class ModelPieChart {
private long userId;
private String twistedName;
private Integer allOrNothing;
private Date workoutDate;
private int DistortedThinkingCount;
查询
@Query("SELECT TableDistortedThinking.allOrNothing, COUNT(TableDistortedThinking.allOrNothing) AS DistortedThinkingCount, TableDistortedThinking.workoutDate, TableDistortedThinking.userId, TableDistortedNames.distortedName AS twistedName " +
"FROM TableDistortedThinking " +
"JOIN TableDistortedNames ON TableDistortedThinking.allOrNothing = TableDistortedNames.pkDistortedNameId " +
"WHERE TableDistortedThinking.workoutDate >= (1000 * strftime('%s', datetime('now', :dateRange)))" +
"AND TableDistortedThinking.userId = :userId " +
"GROUP BY TableDistortedNames.distortedName " +
**他们的查询很长,并且由 UNION ALL 连接,但只有这一部分是真正相关的。 任何导致此崩溃的帮助根将不胜感激。
【问题讨论】:
-
如果您使用的 Android Studio 版本具有 Database Inspector,请使用它来检查您的数据库。您的 Room 架构似乎与实际数据库不一致。
-
我不确定这怎么可能,因为我增加了破坏一切并重新开始的版本号
-
您可以通过查看 Room 为 DAO 生成的
_Impl文件找到一些线索。您可以在标记为java (generated)的app下的项目中找到它。 -
我对关于列不存在的错误消息中
allOrNothing周围的反引号感到困惑。 Room 在生成的 SQL 声明中添加反引号来引用表和列名(请参阅生成的架构),但我希望它们不会进入查询的_Impl代码。 -
这似乎是一个房间错误。见:issuetracker.google.com/issues/157261134
标签: android sqlite android-sqlite android-room