Vlad.mir
Vlad.mir

Reputation: 695

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 !

Upvotes: 0

Views: 481

Answers (2)

Ivan Wooll
Ivan Wooll

Reputation: 4323

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;
}

Upvotes: 1

mohammad jahangiry
mohammad jahangiry

Reputation: 133

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

Upvotes: 1

Related Questions