io.realm.exceptions.RealmException: ShoppingItem is not part of the schema for this Realm


#1

I ran into problem at the line below and the error as title.
RealmResults activeItemResults
= realm.where(ShoppingItem.class).equalTo(“completed”, false)
.findAllSorted(“timestamp”, Sort.DESCENDING);


#2

Can you post the code for your ShoppingItem class, please?


#3
import io.realm.RealmObject;
import io.realm.annotations.PrimaryKey;

public class ShoppingItem extends RealmObject {

    @PrimaryKey
    private String id;
    private String name;
    private String quantity;
    private boolean completed;
    private long timestamp;  // make type long for easier to handle

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getQuantity() {
        return quantity;
    }

    public void setQuantity(String quantity) {
        this.quantity = quantity;
    }

    public boolean isCompleted() {
        return completed;
    }

    public void setCompleted(boolean completed) {
        this.completed = completed;
    }

    public long getTimestamp() {
        return timestamp;
    }

    public void setTimestamp(long timestamp) {
        this.timestamp = timestamp;
    }
} // end class

#4

The class seems fine. Check your gradle configuration.
The ordering rules of applying plugins; try to put:
apply plugin: ‘realm-android’
at the very end, after all others “apply-plugin” statements.

Also try to Build->Clean Project and then Build->Rebuild Project especially if you modified Model classes.


#5

an error when sync after
image

wonder if in the tutorial video that he left out something that he not mentioned in the Realm set up. Because otherwise, it looks straight forward on the videos.


#6

See this:


#7

Error fixed by the two line below in build.gradle (Module: app)

implementation 'io.realm:realm-android:0.87.5'
annotationProcessor 'io.realm:realm-android:0.87.5'