Ambiguous getter for Field… Room persistence library

前端 未结 6 1885
野性不改
野性不改 2021-01-14 00:11

I have the following Entity

public class User {
    @PrimaryKey
    private final long id;

    private String _id;
    private String userName;
    private          


        
6条回答
  •  深忆病人
    2021-01-14 01:12

    As per documentation you need to declare getter for every field.

    I can see that you have not declared your class with @Entity annotation. Also make sure you are using latest version of library as it is still in development you need to expat some ground breaking changes.

    See below example it is working fine for me with below api version of Room.

    api 'android.arch.persistence.room:runtime:1.0.0-alpha8'
    

    Or you can use "alpha9" as well. Hope this will solve your problem.

    @Entity (tableName = "user")
    public class User {
    
    @PrimaryKey
    private int id;
    
    private String _id;
    
    @ColumnInfo(name = "user_name")
    private String userName;
    
    @NonNull
    private String passwrod;
    
    public User(String userName, @NonNull String passwrod) {
        this.userName = userName;
        this.passwrod = passwrod;
    }
    
    @Ignore
    public User() {
    }
    
    public int getId() {
        return id;
    }
    
    public void setId(int id) {
        this.id = id;
    }
    
    public String getUserName() {
        return userName;
    }
    
    public void setUserName(String userName) {
        this.userName = userName;
    }
    
    public String getPasswrod() {
        return passwrod;
    }
    
    public void setPasswrod(String passwrod) {
        this.passwrod = passwrod;
    }
    
    public String get_id() {
        return _id;
    }
    
    public void set_id(String _id) {
        this._id = _id;
    }
    

    }

提交回复
热议问题