2017-09-06 14 views
1

我正在使用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); 
       } 
      } 
     }); 
+0

在代碼中哪裏發生異常?請發佈堆棧跟蹤。還要確保MyModel正在創建並分配給你的數據庫對象。 – Twometer

+3

您可以看到https://stackoverflow.com/a/40213266/2413303以進行猜測。 – EpicPandaForce

+0

非常感謝。它解決了我的問題。你瘋狂的猜測是完美的。 – Ritesh

回答

1

您是否嘗試過更新到最新版本? 定期檢查the Realm changelog是否有錯誤修正是一個不錯的主意。

我有一個類似的問題,並更新到Realm v3.7.2解決了它。在更新日誌中,您可以找到:

當前模式中不存在「'xxx'的崩潰。」當ProGuard啓用時(#5211)。

+1

不,我沒有試過3.7.2版本。現在我正在使用3.7.0。一些proguard規則解決了這個問題。但我將來會使用更新後的版本。 – Ritesh