“io.realm.exceptions.RealmException: '[class_name]' doesn't exist in current schema”, when calling realm.deleteAll () [Realm 4.1.1]

一个人想着一个人 提交于 2020-01-24 19:48:05

问题


I had a RealmAssignment class which was a part of my Realm module. After deleting it, and removing it from the module, I started getting errors when performing realm.deleteAll(). Here is the part of error trace:

Caused by: io.realm.exceptions.RealmException: 'RealmAssignment' doesn't exist in current schema.
   at io.realm.internal.ColumnIndices.getColumnInfo(ColumnIndices.java:112)
   at io.realm.RealmSchema.getColumnInfo(RealmSchema.java:250)
   at io.realm.ImmutableRealmSchema.get(ImmutableRealmSchema.java:41)
   at io.realm.RealmSchema.getAll(RealmSchema.java:88)
   at io.realm.BaseRealm.deleteAll(BaseRealm.java:602)
   at io.realm.Realm.deleteAll(Realm.java:135)`  

I have searched for this error on the internet and these are the things I've tried so far:

  • Disabled instant run
  • Added -keepnames public class * extends io.realm.RealmObject to my proguard-rules.pro file
  • Put apply plugin: 'realm-android' in app level gradle file after all other apply plugin calls
  • Clean, rebuild, invalidate caches and restart

None of the above helped.

I initialize realm using following code:

new RealmConfiguration.Builder()
   .modules(new RealmDefaultModule())
   .deleteRealmIfMigrationNeeded()
   .build();

I have also searched entire project for any reference to "RealmAssignment" class or text containing it, but I found none.

Any help would be greatly appreciated.

EDIT:

This is my RealmDefaultModule class:

@RealmModule(classes = {RealmCheckInVolunteerEvent.class,
        RealmCheckInLocation.class,
        RealmCheckInStaffEvent.class,
        RealmEmail.class,
        RealmInventoryItem.class,
        RealmMember.class,
        RealmMemberAssignment.class,
        RealmOrganizationalUnit.class,
        RealmShift.class,
        RealmSize.class,
        RealmSizeType.class,
        RealmSMS.class,
        RealmTimelineItem.class,
        RealmUser.class,
        RealmUserOrgUnit.class,
        RealmUserSizeType.class,
        RealmUserSize.class})
public class RealmDefaultModule {
}

I initialize my RealmDefaultConfiguration as a singleton, this is the whole class:

public class RealmDefaultConfiguration {

    private static RealmConfiguration myConfig;

    public static synchronized RealmConfiguration getInstance() {
        if (myConfig == null) {
            myConfig = new RealmConfiguration.Builder()
                    .modules(new RealmDefaultModule())
                    .deleteRealmIfMigrationNeeded()
                    .build();
        }
        return myConfig;
    }
}  

(do you think this might be a problem?)

I set my default configuration to the above in my Application class like this:

Realm.init(this);
Realm.setDefaultConfiguration(RealmDefaultConfiguration.getInstance());  

And then in my MainActivity, I call:

Realm realm = Realm.getDefaultInstance();
realm.executeTransaction(new Realm.Transaction() {
            @Override
            public void execute(Realm realm) {
                realm.deleteAll();
            }
        });
realm.close();

来源:https://stackoverflow.com/questions/47201102/io-realm-exceptions-realmexception-class-name-doesnt-exist-in-current-sch

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!