这是android studio中的一个简单的类:
package com.loghty.bahaa.loghty;
import android.arch.persistence.room.ColumnInfo;
import android.arch.persistence.room.Entity;
import android.arch.persistence.room.PrimaryKey;
import android.support.annotation.NonNull;
@Entity (tableName = "Chars")
public class Chars {
@PrimaryKey(autoGenerate = true)
@ColumnInfo(name = "char_Id")
private int pCId;
@NonNull
@ColumnInfo(name = "char_field")
private String mcharField;
// Getters and setters
public String getMcharField() {
return mcharField;
}
public void setMcharField(@NonNull String mcharField) {
this.mcharField = mcharField;
}
public int getpCId() {
return pCId;
}
}
但是,当我构建应用程序时,我在pCId字段中收到此错误:
我检查了很多次代码,但没有什么奇怪的。错误到底在哪里?
最佳答案
将变量从私有(private)更改为 protected 或公共(public)
来自private int pCId;
至protected int pCId;
关于java - 错误: Cannot find getter for field in Android Room,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/51344104/