java.lang.IllegalArgumentException:磁盘上的Realm比指定的更新:v4与v0

时间:2017-06-27 22:25:56

标签: java android realm

用户在我的应用程序中遇到崩溃,我无法自行复制

我得到以下stacktrace:

Fatal Exception: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.app/com.example.app.activities.TasksSublistActivity}: java.lang.IllegalArgumentException: Realm on disk is newer than the one specified: v4 vs. v0
       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2984)
       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3045)
       at android.app.ActivityThread.-wrap14(ActivityThread.java)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1642)
       at android.os.Handler.dispatchMessage(Handler.java:102)
       at android.os.Looper.loop(Looper.java:154)
       at android.app.ActivityThread.main(ActivityThread.java:6776)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410)
Caused by java.lang.IllegalArgumentException: Realm on disk is newer than the one specified: v4 vs. v0
       at io.realm.Realm.createAndValidateFromCache(Realm.java:394)
       at io.realm.Realm.createInstance(Realm.java:348)
       at io.realm.RealmCache.doCreateRealmOrGetFromCache(RealmCache.java:346)
       at io.realm.RealmCache.createRealmOrGetFromCache(RealmCache.java:284)
       at io.realm.Realm.getDefaultInstance(Realm.java:273)
       at com.example.app.TasksSublistActivity.setToolbarTitle(TasksSublistActivity.java:108)
       at com.example.app.activities.TasksSublistActivity.onCreate(TasksSublistActivity.java:66)
       at android.app.Activity.performCreate(Activity.java:6955)
       at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1126)
       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2927)
       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3045)
       at android.app.ActivityThread.-wrap14(ActivityThread.java)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1642)
       at android.os.Handler.dispatchMessage(Handler.java:102)
       at android.os.Looper.loop(Looper.java:154)
       at android.app.ActivityThread.main(ActivityThread.java:6776)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410

在我改变执行Realm迁移的方式之前,这个问题才开始发生。以下是我的SplashActivity中发生的迁移代码:

RealmConfiguration realmConfig = new RealmConfiguration.Builder().schemaVersion(4).migration(new SchemaMigration()).build();
        try (DynamicRealm dynamicRealm = DynamicRealm.getInstance(realmConfig)) {

            if (dynamicRealm.getVersion() != -1 && dynamicRealm.getVersion() < CURRENT_SCHEMA_VERSION) {
                //show progress indicator
                showProgressDialog();

                Completable.fromAction(() -> Realm.migrateRealm(realmConfig))
                        .subscribeOn(Schedulers.io())
                        .observeOn(AndroidSchedulers.mainThread())
                        .subscribe(() -> {
                            progressDialog.dismiss();
                            Realm.setDefaultConfiguration(realmConfig);
                        });

            } else {
                Realm.setDefaultConfiguration(realmConfig);
            }
        }

我的应用程序中的各种活动引发了异常。迁移肯定会成功完成,SplashActivity会在访问Realm的任何其他活动开始之前完成。我只通过调用:

访问任何其他活动中的领域实例
Realm realm = Realm.getDefaultInstance(); 

有谁知道为什么以上会导致这个问题?我的第一个想法是我需要在设置默认配置之前关闭DynamicRealm实例。

0 个答案:

没有答案