gpt4 book ai didi

java - 房间数据库编译错误: Field has non-unique column name

转载 作者:搜寻专家 更新时间:2023-10-30 21:45:41 25 4
gpt4 key购买 nike

我在类(class)的某些领域遇到了这个错误

error: Field has non-unique column name

@Entity(tableName = "Team", foreignKeys = {
@ForeignKey(entity = Group.class, parentColumns = "id", childColumns = "groupId")},
indices = {@Index("groupId")})
public class Team {

@PrimaryKey
private long id;
private long groupId;
@SerializedName("Team")
private String name;
private String englishName;
@SerializedName("Played")
private int played;
@SerializedName("Victories")
private int win;
@SerializedName("Draws")
private int draw;
@SerializedName("Defeats")
private int defeat;
@SerializedName("Made")
private int goalFor;
@SerializedName("Let")
private int goalAgainst;
@SerializedName("Diff")
private int goalDiff;
@SerializedName("Points")
private int points;

public Team() {

}

/* getter and setter methods */
}

例如,我在“win”、“draw”、“groupId”上收到此错误。但不是在“id”或“name”上。如您所见,这是一个编译错误,除了标题中的那句话外,它不再提供有关错误的更多信息。

编辑:我尝试更改变量的名称,但没有成功。

编辑:“win”的 getter 和 setter 方法,其他方法与此方法完全相同。

public int getWin() {
return win;
}

public void setWin(int win) {
this.win = win;
}

最佳答案

您需要添加前缀以避免列名重复。来自官方文档:

前缀字符串前缀 ()指定前缀以在嵌入字段中添加字段的列名。

对于上面的例子,如果我们写成:

@Embedded(prefix = "foo_") Coordinates coordinates;

https://developer.android.com/reference/android/arch/persistence/room/Embedded.html#prefix()

关于java - 房间数据库编译错误: Field has non-unique column name,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50061669/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com