Ambiguous Getter For Field... Room Persistence Library
Solution 1:
You need to have setter and getter for each private field else you should make them public, another reason that may cause this error is having two getters or setters for a field.
Solution 2:
For Room :
In my case
publicStringgetpBSalesTotal() {
return pBSalesTotal;
}
publicvoidsetpBSalesTotal(String pBSalesTotal) {
this.pBSalesTotal = pBSalesTotal;
}
is the previous POJO class that i want as a table in my database.
I have just changed small "" p "" to capital ""P"" and that solved my error
. Like below
publicStringgetPBSalesTotal() {
return pBSalesTotal;
}
publicvoidsetPBSalesTotal(String pBSalesTotal) {
this.pBSalesTotal = pBSalesTotal;
}
to generate this type of
POJO form JSON
you can use this LINK. It worked for Room.
Solution 3:
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")
publicclassUser {
@PrimaryKeyprivate int id;
privateString _id;
@ColumnInfo(name = "user_name")
privateString userName;
@NonNullprivateString passwrod;
publicUser(String userName, @NonNullString passwrod) {
this.userName = userName;
this.passwrod = passwrod;
}
@IgnorepublicUser() {
}
public int getId() {
return id;
}
publicvoidsetId(int id) {
this.id = id;
}
publicStringgetUserName() {
return userName;
}
publicvoidsetUserName(String userName) {
this.userName = userName;
}
publicStringgetPasswrod() {
return passwrod;
}
publicvoidsetPasswrod(String passwrod) {
this.passwrod = passwrod;
}
publicStringget_id() {
return _id;
}
publicvoidset_id(String _id) {
this._id = _id;
}
}
Solution 4:
Return types for getters should be the same as the attribute data type, if you have attribute of data type int, When I found out it fixed my problem.
Good luck.
Solution 5:
Me also face the same issue. While I remove the
"_" underscore symbol, from "_id"
then works fine.
publicclassUser{
@PrimaryKey
privatefinal long id;
privateString myid;
privateString userName;
privateString email;
}
It works for me and I hope it work for others. Thank You.
Post a Comment for "Ambiguous Getter For Field... Room Persistence Library"