Android 房间不使用私有属性
Android Room Not working with private properties
我目前有一个 Note
class。
我已经设置了所有房间注释,它似乎找到了我私有属性的 getter。
这是我的 class:
@Entity(tableName = "notes")
public final class Note {
@PrimaryKey
@ColumnInfo(name = "id")
@NonNull
private final String mId;
@ColumnInfo(name = "title")
@Nullable
private final String mTitle;
@ColumnInfo(name = "desc")
@Nullable
private final String mDesc;
@Ignore
public Note(@Nullable String title, @Nullable String desc) {
this(UUID.randomUUID().toString(), title, desc);
}
public Note(@NonNull String id, @Nullable String title, @Nullable String desc) {
mId = id;
mTitle = title;
mDesc = desc;
}
@NonNull
public String getmId() {
return mId;
}
@Nullable
public String getmTitle() {
return mTitle;
}
@Nullable
public String getmDesc() {
return mDesc;
}
}
一切都在那里,但是当我构建我的项目时。我在 Messages Gradle Build
:
中得到这个
Error:(18, 26) error: Cannot find getter for field.
Error:(22, 26) error: Cannot find getter for field.
Error:(26, 26) error: Cannot find getter for field.
链接回:
private final String mId;
private final String mTitle;
private final String mDesc;
但我确实有吸气剂,它们是 public。
我目前正在使用:
implementation "android.arch.persistence.room:runtime:1.1.0-alpha3"
annotationProcessor "android.arch.persistence.room:compiler:1.1.0-alpha3"
对于Room
有什么想法吗?
Room 正在为例如 mId 属性 寻找 getter 方法,按照惯例,mId 是 getMId 而不是 getmId。
我建议将字段重命名为 id、title、desc 和 mehtods 为 getId() getTitle() 和 getDesc() 以提高可读性。
我目前有一个 Note
class。
我已经设置了所有房间注释,它似乎找到了我私有属性的 getter。
这是我的 class:
@Entity(tableName = "notes")
public final class Note {
@PrimaryKey
@ColumnInfo(name = "id")
@NonNull
private final String mId;
@ColumnInfo(name = "title")
@Nullable
private final String mTitle;
@ColumnInfo(name = "desc")
@Nullable
private final String mDesc;
@Ignore
public Note(@Nullable String title, @Nullable String desc) {
this(UUID.randomUUID().toString(), title, desc);
}
public Note(@NonNull String id, @Nullable String title, @Nullable String desc) {
mId = id;
mTitle = title;
mDesc = desc;
}
@NonNull
public String getmId() {
return mId;
}
@Nullable
public String getmTitle() {
return mTitle;
}
@Nullable
public String getmDesc() {
return mDesc;
}
}
一切都在那里,但是当我构建我的项目时。我在 Messages Gradle Build
:
Error:(18, 26) error: Cannot find getter for field.
Error:(22, 26) error: Cannot find getter for field.
Error:(26, 26) error: Cannot find getter for field.
链接回:
private final String mId;
private final String mTitle;
private final String mDesc;
但我确实有吸气剂,它们是 public。
我目前正在使用:
implementation "android.arch.persistence.room:runtime:1.1.0-alpha3"
annotationProcessor "android.arch.persistence.room:compiler:1.1.0-alpha3"
对于Room
有什么想法吗?
Room 正在为例如 mId 属性 寻找 getter 方法,按照惯例,mId 是 getMId 而不是 getmId。
我建议将字段重命名为 id、title、desc 和 mehtods 为 getId() getTitle() 和 getDesc() 以提高可读性。