简体   繁体   中英

error: Cannot find setter for field - Room

I don't really know why I have this error. The code seems pretty straight forward.

@Entity(indices = {@Index("clientLocalId")})
.
.

private @PrimaryKey String clientLocalId;


public String getClientLocalId() {
    return clientLocalId;
}

public void setClientLocalId(long idInvoice, String receipt) {
    this.clientLocalId = String.valueOf(idInvoice) + " " + receipt;
}

I tried to changed the name in just client , restarted and cleared caches, same error.

error: Cannot find setter for field. private @PrimaryKey String clientLocalId; ^

Any idea is appreciated. Thanks in advance !

it happened because of the second Parameter receipt of clientLocalId , remove it or add another setter method, i recommend you add receipt to your clientLocalId out of entity class before inserting in Database

Room is looking for a setter that just takes a single String value. Your method has two.

Change it to the below and use another method to create your concatenated id.

public void setClientLocalId(String id) {
    this.clientLocalId = id;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM