![](/img/trans.png)
[英]How to add room auto generated Primary key to another entity as a foreign key
[英]How to properly annotate object variables that are part of primary key in Room entity?
我收到一个错误:“您必须使用@NonNull注释主键。“名称”可以为空。
我不明白此错误的根源,因为我非常清楚地用声明为组合主键一部分的@NonNull注释了我的String变量“ name”。 我是否错误地设置了组合主键?
@Entity(tableName = "ScavItems",
primaryKeys = { "scavHuntID", "name" },
foreignKeys = {
@ForeignKey(entity = ScavHunt.class,
parentColumns = "shID",
childColumns = "scavHuntID")
})
public class ScavItem {
@NonNull private int scavHuntID;
@NonNull private String name;
@ColumnInfo(name = "found")
private boolean found;
public ScavItem(int scavHuntID, String name){
this.scavHuntID = scavHuntID;
this.name = name;
found = false;
}
public String getName(){ return this.name; }
public boolean getFound(){ return this.found; }
public int getScavHuntID(){ return this.scavHuntID; }
public void setFound(boolean found){ this.found = found; }
}
我想到了。 我正在导入错误的NonNull程序包。 这是正确的导入:
import android.support.annotation.NonNull;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.