首页 > 解决方案 > 由于未找到列,房间数据库崩溃

问题描述

当运行查询以从房间数据库返回一些数据时,我在 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 连接,但只有这部分是真正相关的。任何导致此崩溃的帮助根将不胜感激。

标签: androidsqliteandroid-sqliteandroid-room

解决方案


此故障是由运行 API 25 或更低版本的设备上发生的 Room 错误引起的。它在房间版本 2.3.0-alpha02 中得到修复。有关详细信息,请参阅Google IssueTracker中的说明。


推荐阅读