问题描述
运行查询以从会议室数据库返回一些数据时,我在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连接,但是只有这一部分才是真正相关的。 引起崩溃的任何帮助根源将不胜感激。
解决方法
此故障是由运行API 25或更低版本的设备上发生的Room错误引起的。它在会议室版本2.3.0-alpha02中已修复。有关更多详细信息,请参见description in the Google IssueTracker。