Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

You must annotate primary keys with @NonNull?

I'm getting this error on this piece of code. You must annotate primary keys with @NonNull. "uidString" is nullable. When I annotate it with @NonNull and @PrimaryKey, An entity must have at least 1 field annotated with @PrimaryKey

What's up?

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;

like image 848
microflakes Avatar asked Nov 12 '19 21:11

microflakes


1 Answers

For Java you should annotate with @android.support.annotation.NonNull

Delete the other NonNull import you are using yet and change it to

import android.support.annotation.NonNull;

Then use both annotations

@PrimaryKey
@NonNull
like image 92
otto Avatar answered Sep 20 '22 17:09

otto