![](/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.