
这是一个POJO示例
public class Product{ private long ID; private String name; private double price; ... constructor for all fIElds ... getters and setters}现在,在我的productDAO中,如果我有这样的查询
@query(select ID, name from products)liveData<List<Product>> getProducts()我得到一个错误:
The columns returned by the query does not have the fIElds [price] in
… Product even though they are annotated as non-null or primitive.
Columns returned by the query: [ID,name]
a)如果我进入我的产品并设置
@Nullableprivate double price;错误仍然存在.
b)如果我进入我的产品并设置
@Ignoreprivate double price;错误消失,但如果我有另一个查询
@query(select p.ID, p.name, p.price, t.someFIEld from products p inner join table t) liveData<List<Product>> getJoinqueryResponse()因为设置了@Ignore,价格返回为0.0.
那么如何解决这个问题?希望我不需要为房间的每个不同响应制作一个POJO …
解决方法:
原始类型默认不为null.使价格加倍,这将解决问题,因为它可以为空.此外,您可以添加自定义getter以避免将price作为null对象.
public double getPrice(){ if(this.price == null) return 0.0; return this.price;}@Ingore告诉Room完全忽略这个字段,根据你的答案,这不是你的意思.
总结以上是内存溢出为你收集整理的android – room error:查询返回的列没有字段fieldname全部内容,希望文章能够帮你解决android – room error:查询返回的列没有字段fieldname所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)