gpt4 book ai didi

android - Realm Android : io. realm.exceptions.RealmException: 'DomainModel' 在当前架构中不存在

转载 作者:行者123 更新时间:2023-11-30 00:22:11 25 4
gpt4 key购买 nike

我在 android 应用程序中使用 Realm 数据库我已经按照文档集成了 Realm 数据库,如下所示:

build.gradle(项目级别)

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(应用级别)

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

以下是MyApplication类中的代码

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;
}
}

现在,就调试版本而言,应用程序按预期运行,没有任何崩溃。但是当我生成一个发布版本时,应用程序崩溃了

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

请看一下上面的代码,请帮我解决这个崩溃问题。提前致谢。

注意:我正在访问一个 Realm 对象作为

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 类的方式

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);
}
}
});

最佳答案

您尝试过更新到最新版本吗?定期检查 the Realm changelog 是个好主意错误修正。

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

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

关于android - Realm Android : io. realm.exceptions.RealmException: 'DomainModel' 在当前架构中不存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46070608/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com