我是Android开发的新手,我正在尝试构建一个简单的应用笔记。
我决定使用Realm而不是SQLite,但我无法弄清楚如何将数据库中的所有内容连接到我的RecyclerView,所以我在他们的GitHub上找到了一个关于为RecyclerViews创建适配器的示例领域DB。
我复制了大部分代码并对其进行了编辑以适应我的应用程序,但现在它在启动时崩溃,我不知道是什么导致它,因为堆栈跟踪没有显示任何内容。
我已将应用程序上传到GitHub上的this repo,供人们查看并告诉我可能出现的问题。
答案 0 :(得分:0)
例外是在日志中。也许您在视图中应用了过滤器?
问题是您正在错误地初始化Realm。
03-31 15:56:54.403 8728 8728 E AndroidRuntime: java.lang.RuntimeException: Unable to create application com.odinuts.memo.app.MyApplication: java.lang.IllegalStateException: Call `Realm.init(Context)` before creating a RealmConfiguration
03-31 15:56:54.403 8728 8728 E AndroidRuntime: at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5364)
03-31 15:56:54.403 8728 8728 E AndroidRuntime: at android.app.ActivityThread.-wrap2(ActivityThread.java)
03-31 15:56:54.403 8728 8728 E AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1528)
03-31 15:56:54.403 8728 8728 E AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:102)
03-31 15:56:54.403 8728 8728 E AndroidRuntime: at android.os.Looper.loop(Looper.java:154)
03-31 15:56:54.403 8728 8728 E AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:6077)
03-31 15:56:54.403 8728 8728 E AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method)
03-31 15:56:54.403 8728 8728 E AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
03-31 15:56:54.403 8728 8728 E AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
03-31 15:56:54.403 8728 8728 E AndroidRuntime: Caused by: java.lang.IllegalStateException: Call `Realm.init(Context)` before creating a RealmConfiguration
03-31 15:56:54.403 8728 8728 E AndroidRuntime: at io.realm.RealmConfiguration$Builder.<init>(RealmConfiguration.java:399)
03-31 15:56:54.403 8728 8728 E AndroidRuntime: at io.realm.RealmConfiguration$Builder.<init>(RealmConfiguration.java:394)
03-31 15:56:54.403 8728 8728 E AndroidRuntime: at com.odinuts.memo.app.MyApplication.onCreate(MyApplication.java:13)
03-31 15:56:54.403 8728 8728 E AndroidRuntime: at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1024)
03-31 15:56:54.403 8728 8728 E AndroidRuntime: at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5361)
03-31 15:56:54.403 8728 8728 E AndroidRuntime: ... 8 more
修改:在Android Studio中,检查您的Android Monitor
标签,确保以下过滤条件正确
1) Process (this should be your app
2) Regex/selection (select your app, or no filters)
3) Log level (debug, info, error, etc)
4) Device (in case you have several)
答案 1 :(得分:0)
基本上你只需要在RealmConfiguration
之前添加Realm.init(this);