我收到此错误:
Fatal Exception: java.lang.IllegalArgumentException
Configurations cannot be different if used to open the same file. Cached configuration: realmFolder: /data/user/0/nl.hgrams.passenger/files realmFileName : myrealm.realm canonicalPath: /data/data/nl.hgrams.passenger/files/myrealm.realm key: [length: 0] schemaVersion: 3 migration: null deleteRealmIfMigrationNeeded: false durability: FULL schemaMediator: io.realm.DefaultRealmModuleMediator@ea820c5a New configuration: realmFolder: /data/user/0/nl.hgrams.passenger/files realmFileName : myrealm.realm canonicalPath: /data/data/nl.hgrams.passenger/files/myrealm.realm key: [length: 0] schemaVersion: 3 migration: null deleteRealmIfMigrationNeeded: true durability: FULL schemaMediator: io.realm.DefaultRealmModuleMediator@ea820c5a
这里:
io.realm.RealmCache.validateConfiguration (RealmCache.java:226)
io.realm.RealmCache.createRealmOrGetFromCache (RealmCache.java:103)
io.realm.Realm.getInstance (Realm.java:197)
在这一行:
Realm realm = Realm.getInstance(PSLocationCenter.getInstance().Config);
我的配置是这样完成的:
Realm realm = null, realmActive = null;
try {
// should throw as migration is required
Log.i("", "migration entered here, tried to open");
if (Config == null) {
Config = new RealmConfiguration.Builder(PSLocationCenter.this).name("myrealm.realm").schemaVersion(3).build();
}
if (activeConfig == null) {
activeConfig = new RealmConfiguration.Builder(PSLocationCenter.this).name("active.realm").schemaVersion(2).build();
}
realm = Realm.getInstance(Config);
realmActive = Realm.getInstance(activeConfig);
} catch (RealmMigrationNeededException ex) {
if(realm != null)
realm.close();
if(realmActive != null)
realmActive.close();
Config = new RealmConfiguration.Builder(PSLocationCenter.this).name("myrealm.realm").schemaVersion(3).deleteRealmIfMigrationNeeded().build();
activeConfig = new RealmConfiguration.Builder(PSLocationCenter.this).name("active.realm").schemaVersion(2).deleteRealmIfMigrationNeeded().build();
PSLocationCenter.getInstance().pref.setAuthenticationToken(null);
}
我的问题是,如何关闭/关闭打开文件的配置,以便使用第二个配置(带有 deleteRealmIfMigrationNeeded 的配置?