room error: The columns returned by the query does not have the fields fieldname

后端 未结 1 410
被撕碎了的回忆
被撕碎了的回忆 2021-01-17 17:41

Here is a sample POJO

public class Product{
  private long id;
  private String name;
  private double price;

 ... constructor for all fields
 ... getters a         


        
相关标签:
1条回答
  • 2021-01-17 18:01

    Primitive types are by default not null. Make the price Double and this will solve the issue since it will be nullable then. Furthermore, you can add a custom getter to avoid having price as a null object.

    public double getPrice(){
        if(this.price == null) return 0.0;
        return this.price;
    }
    

    @Ingore tells Room to ignore the field altogether, which is not what you want, based on your answer.

    0 讨论(0)
提交回复
热议问题