我正在使用Android应用程序领域的分贝我已经集成领域分贝按照文件主要内容如下:境界安卓:io.realm.exceptions.RealmException:“的DomainModel”并不在当前架构存在
构建.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”不存在当前 模式存在。
请看看上面的代码,请帮我解决这个崩溃。提前致谢。
注:我访问境界对象作为
境界的境界= 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);
}
}
});
在代码中哪里发生异常?请发布堆栈跟踪。还要确保MyModel正在创建并分配给你的数据库对象。 – Twometer
您可以看到https://stackoverflow.com/a/40213266/2413303以进行猜测。 – EpicPandaForce
非常感谢。它解决了我的问题。你疯狂的猜测是完美的。 – Ritesh