【问题标题】:My android app crashes on launch, and the stack trace doesn't show anything我的 android 应用程序在启动时崩溃,并且堆栈跟踪没有显示任何内容
【发布时间】:2017-03-31 14:53:40
【问题描述】:

我是 android 开发新手,我正在尝试构建一个简单的笔记应用程序。

我决定使用 Realm 而不是 SQLite,但我不知道如何将数据库上的所有内容连接到我的 RecyclerView,所以我在他们的 GitHub 上找到了一个示例,关于为 RecyclerViews 创建适配器,该适配器显示来自领域数据库。

我复制了大部分代码并对其进行了编辑以适合我的应用程序,但现在它在启动时崩溃了,我不知道是什么原因造成的,因为堆栈跟踪没有显示任何内容。

我已将应用程序上传到 GitHub 上的 this repo,供人们查看并告诉我可能出现的问题。

【问题讨论】:

    标签: android android-recyclerview realm


    【解决方案1】:

    基本上你只需要在 RealmConfiguration 之前添加Realm.init(this);

    【讨论】:

      【解决方案2】:

      异常在日志中。也许您在视图中应用了过滤器?

      问题是你初始化 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)
      

      【讨论】:

      • 谢谢。我怎么知道我是否有过滤器?我不认为我这样做
      猜你喜欢
      • 2015-09-11
      • 2019-07-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-07-11
      • 2012-06-08
      • 1970-01-01
      • 2011-04-25
      相关资源
      最近更新 更多