You must annotate primary keys with @NonNull?

you must annotate primary keys with @nonnull id
room not null annotation
android-room primary key
android-room primary key string
error annotation value must be a class literal room database
room columninfo not null
android-room without primary key
kotlin room not null

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;

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

App Crash by `@NonNull` and Android Room, Since you now know @NonNull annotation, you could eager to apply it. However, you should be cautious for @Entity class because that will� I am getting an error: "You must annotate primary keys with @NonNull. "name" is nullable."

You can try binding the primary key with the Entity like this:

@Entity(tableName = "player_profiles",
        primaryKeys = { "uidString" })

After that annotate your primary key with @NonNull in the class below.

@NonNull
public String uidString = UUID.randomUUID().toString();

A step by step migration to Room. So you're maintaining an old app , We must annotate the variable we want to use as primary key with @PrimaryKey and @NonNull. Here is the code for my “Stores” table, with� java - support - you must annotate primary keys with @nonnull android Android @NonNull usefulness (2) After a few reading and questions like this one I was wondering if there was a point in using @NonNull Android Support Annotation.

check the case sensitiveness it should be "@NonNull" and not "@Nonnull" import androidx.annotation.NonNull;

How to annotate Column as NOT NULL using Android Room , For Java you should annotate with #android.support.annotation. if you have an autogenerated primary key, you should write so: #Entity(tableName = "story")� This entity has three fields. Unless you set to ignore, each field will represent each column in a table. Suppose you released the app with this entity. In the application, an email value is considered as not null. Since you now know @NonNull annotation, you could eager to apply it. So far, that has been recommended without any doubt.

[PDF] Room: the blessed object mapper, error: You must annotate primary keys with. @NonNull. SQLite considers this a bug and Room does not allow it. Page 13. Entities. The @nonnull annotation can be seen as a precondition that is used for static analysis by the tool FindBugs. If you prefer an approach such as runtime-assertion checking, i.e. the fail first strategy, you should consider using assertion statements as built-in Java.

PrimaryKey, If you would like to define a composite primary key, you should use If PrimaryKey annotation is used on a Embedded d field, all columns� As with PRIMARY KEYs, a UNIQUE table-constraint clause must contain only column names — the use of expressions in an indexed-column of a UNIQUE table-constraint is not supported. In most cases, UNIQUE and PRIMARY KEY constraints are implemented by creating a unique index in the database.

Defining data using Room entities, Use a primary key. Each entity must define at least 1 field as a primary key. Even when there is only 1 field, you still need to annotate the field� Tip on auto-generating keys: To auto-generate a unique key for each entity, you would add and annotate a primary integer key with autoGenerate=true. See Defining data using Room entities . The data access object, or Dao , is an annotated class where you specify SQL queries and associate them with method calls.

Comments
  • When I annotate it with @NonNull, An entity must have at least 1 field annotated with @PrimaryKey Did you annotate it with both or just @NonNull?
  • The latter is with both. I tired changing the order too
  • And make sure you import the correct NonNull package: import android.support.annotation.NonNull;
  • Yes, sorry for the sloppy code paste, all are present. OP edited
  • I have tried out what you did and I did not get any compile or build errors. The problem is elsewhere and not with the annotations. Also, I used the AndroidX annotations and NOT the support annotations
  • :( still getting the second error about atleast 1 primary key
  • Also make sure that you try the other import package for NonNull mentioned in my comment to OP: import android.support.annotation.NonNull
  • That is, in fact, what the text in the question says.