Android领域:io.realm.exceptions.RealmException:当前架构中不存在"DomainModel" [英] Realm Android : io.realm.exceptions.RealmException: 'DomainModel' doesn't exist in current schema

查看:367
本文介绍了Android领域:io.realm.exceptions.RealmException:当前架构中不存在"DomainModel"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在android应用程序中使用领域db,我已经按照文档集成了领域db,如下所示:

I am using realm db in android application I have integrated realm db as per documents which is as follows:

build.gradle(项目级别)

build.gradle(Project Level)

dependencies {
        classpath 'com.android.tools.build:gradle:2.3.3'
        classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4'
        classpath "io.realm:realm-gradle-plugin:3.7.0"
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }

build.gradle(应用程序级别)

build.gradle(App level)

apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
apply plugin: 'com.neenbedankt.android-apt'
apply plugin: 'realm-android'

以下是MyApplication类中的代码

following is code in MyApplication Class

Realm.init(this);
        RealmConfiguration config = new RealmConfiguration.Builder()
                .name(Realm.DEFAULT_REALM_NAME)
                .schemaVersion(1)
                .deleteRealmIfMigrationNeeded()
                .build();

        Realm.getInstance(config);
        Realm.setDefaultConfiguration(config);

模型类

public class MyModel extends RealmObject {

    @PrimaryKey
    @SerializedName("message")
    private String message;

    @SerializedName("session_expired")
    private Integer sessionExpired;

    @SerializedName("domain_name")
    private String domainName;

    public String getDomainName() {
        return domainName;
    }

    public void setDomainName(String domainName) {
        this.domainName = domainName;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Integer getSessionExpired() {
        return sessionExpired;
    }

    public void setSessionExpired(Integer sessionExpired) {
        this.sessionExpired = sessionExpired;
    }
}

现在,就调试构建而言,应用程序可以按预期运行,而不会崩溃. 但是当我生成发布版本时,应用会因

Now, As far as debug build is concern, app is running as expected without any crash. But when I generate a release build, app get crash with

io.realm.exceptions.RealmException:当前不存在"MyModel" 模式.

io.realm.exceptions.RealmException: 'MyModel' doesn't exist in current schema.

请查看上面的代码,并请帮助我解决此崩溃问题.提前谢谢.

Please take a look at above code and please help me solve this crash. Thanks In advance.

注意:我以

领域realm = Realm.getDefaultInstance();

Realm realm = Realm.getDefaultInstance();

以下是堆栈跟踪

E/AndroidRuntime: FATAL EXCEPTION: main
                                                                   io.realm.exceptions.RealmException: 'MyModel' doesn't exist in current schema.
                                                                       at and.c(SourceFile:5112)
                                                                       at ans.a(SourceFile:48)
                                                                       at aon.a(SourceFile:68)
                                                                       at aop.d(SourceFile:285)
                                                                       at aop.a(SourceFile:178)
                                                                       at anb.a(SourceFile:3261)
                                                                       at abh.c(SourceFile:259)
                                                                       at com.mpose.com.mpose.activity.LoginActivity.k(SourceFile:306)
                                                                       at abh.b(SourceFile:1219)
                                                                       at com.mpose.com.mpose.activity.LoginActivity.loginClick(SourceFile:134)
                                                                       at com.mpose.com.mpose.activity.LoginActivity$$ViewBinder$1.doClick(SourceFile:18)
                                                                       at butterknife.internal.DebouncingOnClickListener.onClick(SourceFile:22)
                                                                       at android.view.View.performClick(View.java:4084)
                                                                       at android.view.View$PerformClick.run(View.java:16966)
                                                                       at android.os.Handler.handleCallback(Handler.java:615)
                                                                       at android.os.Handler.dispatchMessage(Handler.java:92)
                                                                       at android.os.Looper.loop(Looper.java:137)
                                                                       at android.app.ActivityThread.main(ActivityThread.java:4745)
                                                                       at java.lang.reflect.Method.invokeNative(Native Method)
                                                                       at java.lang.reflect.Method.invoke(Method.java:511)
                                                                       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
                                                                       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
                                                                       at dalvik.system.NativeStart.main(Native Method)

这是我访问MyModel类的方式

Here Is how I am accessing MyModel class

final RealmQuery<MyModel> query = mRealm.where(MyModel.class).equalTo("message", "Success");
        RealmResults<MyModel> result = query.findAll();

        mRealm.executeTransaction(new Realm.Transaction() {
            @Override
            public void execute(Realm realm) {
                MyModel myModel = query.findFirst();
                if (myModel != null) {
                    myModel.setDomainName(strDomain);
                }
            }
        });

推荐答案

您是否尝试过更新到最新版本? 定期检查领域变更日志修正错误.

Have you tried to update to the latest version? It's a nice idea to regularly check the Realm changelog for bugfixes.

我遇到了类似的问题,并且更新到Realm v3.7.2即可解决.在更改日志中,您可以找到:

I was having a similar issue and updating to Realm v3.7.2 solved it. In the changelog you can find:

当前架构中不存在带有'xxx'的崩溃".启用ProGuard时(#5211).

Crash with "'xxx' doesn't exist in current schema." when ProGuard is enabled (#5211).

这篇关于Android领域:io.realm.exceptions.RealmException:当前架构中不存在"DomainModel"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆