我在这段代码中得到了这个错误。You must annotate primary keys with @NonNull. "uidString" is nullable.
当我用@ Nonkey和@PrimaryKey注解它时,An entity must have at least 1 field annotated with @PrimaryKey
怎么了?
import androidx.annotation.NonNull;
import androidx.room.ColumnInfo;
import androidx.room.Entity;
import androidx.room.PrimaryKey;
import java.util.UUID;
@Entity(tableName = "player_profiles")
public class PlayerGameProfile implements Parcelable {
@PrimaryKey
public String uidString = UUID.randomUUID().toString();
@ColumnInfo(name = "name")
public String name;
字符串
4条答案
按热度按时间hk8txs481#
对于Java,您应该使用
@android.support.annotation.NonNull
进行注解删除您正在使用的另一个非同步导入,并将其更改为
字符串
然后使用这两个注解
型
krcsximq2#
在我的情况下,我有:
字符串
而不是:
型
r8uurelv3#
您可以尝试像这样将主键与实体绑定:
字符串
然后在下面的类中用
@NonNull
注解你的主键。型
rseugnpd4#
检查大小写敏感性,它应该是“@Nonnull”而不是“@Nonnull”import androidx.annotation.Nonnull;