问题
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.RealmObjectto my proguard-rules.pro file - Put
apply plugin: 'realm-android'in app level gradle file after all otherapply plugincalls - 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