本文介绍了尝试构建RealmConfiguration时,Realm导致我的应用程序崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将Realm用作我的应用程序中得分较高的数据库.但是,当这行代码被调用时:

I'm trying to use Realm as a database for high scores in my app. However, when this line of code is called:

realmConfig = new RealmConfiguration.Builder(getActivity().getApplicationContext()).build();

在我要保存用户分数的片段中,我得到了:

in the Fragment where I'm trying to save the user's score, I get this:

FATAL EXCEPTION: main
Process: com.tommy.mastersproject, PID: 21387
Theme: themes:{com.android.settings=overlay:com.cyngn.hexo, default=overlay:system, iconPack:system, fontPkg:system, com.android.systemui=overlay:system, com.android.systemui.navbar=overlay:system}
java.lang.NoClassDefFoundError: Failed resolution of: Lio/realm/RealmConfiguration$Builder;
at com.tommy.mastersproject.fragments.MemoryRecallFragment.onCreate(MemoryRecallFragment.java:144)
at android.support.v4.app.Fragment.performCreate(Fragment.java:1951)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1029)
at android.support.v4.app.BackStackRecord.setLastIn(BackStackRecord.java:779)
at android.support.v4.app.BackStackRecord.calculateFragments(BackStackRecord.java:802)
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:660)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1617)
at android.support.v4.app.FragmentController.execPendingActions(FragmentController.java:339)
at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:601)
at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1238)
at android.app.Activity.performStart(Activity.java:6268)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2413)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2510)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1363)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5461)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.lang.ClassNotFoundException: Didn't find class "io.realm.RealmConfiguration$Builder" on path: DexPathList[[dex file "/data/data/com.tommy.mastersproject/files/instant-run/dex/slice-support-annotations-23.4.0_d80f4a0fc2ae8e1f7cf76e4c536a48795da28487-classes.dex", dex file "/data/data/com.tommy.mastersproject/files/instant-run/dex/slice-slice_9-classes.dex", dex file "/data/data/com.tommy.mastersproject/files/instant-run/dex/slice-slice_8-classes.dex", dex file "/data/data/com.tommy.mastersproject/files/instant-run/dex/slice-slice_7-classes.dex", dex file "/data/data/com.tommy.mastersproject/files/instant-run/dex/slice-slice_6-classes.dex", dex file "/data/data/com.tommy.mastersproject/files/instant-run/dex/slice-slice_5-classes.dex", dex file "/data/data/com.tommy.mastersproject/files/instant-run/dex/slice-slice_4-classes.dex", dex file "/data/data/com.tommy.mastersproject/files/instant-run/dex/slice-slice_3-classes.dex", dex file "/data/data/com.tommy.mastersproject/files/instant-run/dex/slice-slice_2-classes.dex", dex file "/data/data/com.tommy.mastersproject/files/instant-run/dex/slice-slice_1-classes.dex", dex file "/data/data/com.tommy.mastersproject/files/instant-run/dex/slice-slice_0-classes.dex", dex file "/data/data/com.tommy.mastersproject/files/instant-run/dex/slice-library-2.4.0_e0d22a6e7ea9a4d2326a0c8c16bbc09d4d04442c-classes.dex", dex file "/data/data/com.tommy.mastersproject/files/instant-run/dex/slice-internal_impl-23.4.0_bd67bdb6ef0c094e8f4157e2567e8b30b9d0dd7f-classes.dex", dex file "/data/data/com.tommy.mastersproject/files/instant-run/dex/slice-com.jakewharton-butterknife-8.0.1_9246a0d023a2de89ba20a84f0fb1ecc6b733b004-classes.dex", dex file "/data/data/com.tommy.mastersproject/files/instant-run/dex/slice-com.code-troopers.betterpickers-library-3.0.0_f98f8b23c6650d93d8479a647f8f2162db8834e8-classes.dex", dex file "/data/data/com.tommy.mastersproject/files/instant-run/dex/slice-com.astuetz-pagerslidingtabstrip-1.0.1_474986b4f5d06e547dc72e3bf0988a95fa9d3973-classes.dex", dex file "/data/data/com.tommy.mastersproject/files/instant-run/dex/slice-com.android.support-support-vector-dr

我也尝试使用

realm = Realm.getDefaultInstance();

但没有任何运气.

在Google的快速搜索中,也有类似的投诉,这是由于Realm与Android multidex的兼容性差以及未与Gradle保持最新关系,但我目前正在运行Gradle 2.1.2.

From a quick Google search, there have been similar complaints which were due to Realm's poor compatibility with the Android multidex and for not being up-to-date with Gradle, but I'm currently running Gradle 2.1.2.

推荐答案

我也在使用Gradle 2.1.2,并且Realm运行正常,问题可能与Instant Run有关,您是否尝试在没有Instant Run的情况下加载项目?如果没有禁用它(在Android Studio->首选项->构建,执行,部署->即时运行中),请清理项目并再次运行.

I am also using Gradle 2.1.2 and Realm is working perfectly fine, problem could be with Instant Run, Did you try loading the project without Instant Run? If not disable it(In Android studio -> Preferences -> Build, Execution, Deployment -> Instant Run), clean the project and run it again.

如果它不起作用,请在创建RealmConfiguration并使用Realm的地方共享实际代码.

If it does not work, share the actual code where you are creating RealmConfiguration and using Realm.

这篇关于尝试构建RealmConfiguration时,Realm导致我的应用程序崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 02:05