简体   繁体   中英

Realm Object is not part of the schema for this Realm

I'm using realm as database for my app and i have model SessionModel :

public class SessionModel extends RealmObject {

    private long id;

    private int currentPomod;

    private int state;

    ...getters\setters
}

When i'm trying to create new document in database:

Realm.init(this);

realm = Realm.getDefaultInstance();

realm.beginTransaction();
realm.copyToRealm(defSession);

I got this error: java.lang.IllegalArgumentException: SessionModel is not part of the schema for this Realm

My top level gradle file contains this dependencies:

...
dependencies {
    classpath 'com.android.tools.build:gradle:2.2.3'

    classpath "io.realm:realm-gradle-plugin:2.3.0"

    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
}
...

and app gradle module applying this plugins (ont top of build.gradle module app file):

apply plugin: 'com.android.application'
apply plugin: 'realm-android'

...

Instant Run disabled.

在我的情况下是以下情况: MyClass正在实现RealmModel ,但未使用@RealmClass注释

Found some solution from git issues . Its looking like same problem you have.

Solution: apply apply plugin: 'com.neenbedankt.android-apt' before apply plugin: 'realm-android'

Hope it will help you!!

Encountered this error just now. I tried rearranging my plugins still didnt work. Turns out since I am using a managed realmList now for automatic update, I have to change the realm config as well on the application. just delete your current realm. using this Realm.deleteRealm(realmConfig); then start again but just comment the code out.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM