Ambiguous getter for Field... Room persistence library

Viewed 7726

I have the following Entity

public class User {
    @PrimaryKey
    private final long id;

    private String _id;
    private String userName;
    private String email;
}

However when I try to create table for this entity in android using room persistence library, I get the following error.

Error:(18, 20) error: Ambiguous getter for Field(element=_id, name=_id, type=java.lang.String, affinity=TEXT, columnName=_id, parent=null, indexed=false). All of the following match: getId, get_id. You can @Ignore the ones that you don't want to match.

The _id field is included so that I can directly translate the responses from the node.jsapi hooked up to a mongodb database.

6 Answers

For Room :

In my case

public String getpBSalesTotal() {
    return pBSalesTotal;
}

public void setpBSalesTotal(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

public String getPBSalesTotal() {
    return pBSalesTotal;
}

public void setPBSalesTotal(String pBSalesTotal) {
    this.pBSalesTotal = pBSalesTotal;
}

to generate this type of

POJO form JSON

you can use this LINK. It worked for Room.

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.

Me also face the same issue. While I remove the

"_" underscore symbol, from "_id"

then works fine.

public class User {
    @PrimaryKey
    private final long id;

    private String myid;
    private String userName;
    private String email;
}

It works for me and I hope it work for others. Thank You.

If this happens again, I would highly suggest you to autogenerate the getter and/or the setter with the help from Android Studio.

This way you won't risk using time on this issue again.

To see how, please check this SO-answer

Related