android - 由于未找到列,房间数据库崩溃
问题描述
当运行查询以从房间数据库返回一些数据时,我在 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 中得到修复。有关详细信息,请参阅Google IssueTracker中的说明。
推荐阅读
- r - 如何读取R中动态分配内存的大数据文件?
- c# - 如何旋转并将对象移动到另一个对象位置和旋转?
- git - 将合并信息添加到 Git 历史记录
- githooks - 如何在 gitkraken 中禁用 git 钩子?
- node.js - Node.js 不等待嵌套的 http 调用完成
- java - 将 StringTokenizer 与逗号分隔符一起使用,同时保持逗号前面有反斜杠
- python - 如何在python中为类属性添加方法?
- asp.net-core - 在 .NET Core 构建/发布中向 web.config 添加配置
- visual-studio-code - 更改 vscode-icons 上的默认文件扩展名图标不起作用
- c# - 函数之间的区别
和匿名异步等待动作