由于找不到列,导致会议室数据库崩溃

问题描述

运行查询以从会议室数据库返回一些数据时,我在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