Fatal Exception: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mandarine.sai/com.mandarine.sai.features.main.MainActivity}: java.lang.IllegalStateException: Call `Realm.init(Context)` before calling this method.
at android.app.ActivityThread.performLaunchActivity + 2814(ActivityThread.java:2814)
at android.app.ActivityThread.handleLaunchActivity + 2892(ActivityThread.java:2892)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage + 1613(ActivityThread.java:1613)
at android.os.Handler.dispatchMessage + 106(Handler.java:106)
at android.os.Looper.loop + 176(Looper.java:176)
at android.app.ActivityThread.main + 6635(ActivityThread.java:6635)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run + 547(RuntimeInit.java:547)
at com.android.internal.os.ZygoteInit.main + 823(ZygoteInit.java:823)
和IllegalStateException
Caused by java.lang.IllegalStateException: Call `Realm.init(Context)` before calling this method.
at io.realm.Realm.getDefaultInstance + 349(Realm.java:349)
at com.mandarine.sai.model.db.RealmManager.getDefaultInstance + 53(RealmManager.java:53)
at com.mandarine.sai.model.db.ConnectionsRepository.getAllActiveConnections + 99(ConnectionsRepository.java:99)
at com.mandarine.sai.features.authorizations.common.ConnectionAndKeyCollectorKt.collectConnectionsAndKeys + 39(ConnectionAndKeyCollectorKt.java:39)
at com.mandarine.sai.features.authorizations.list.AuthorizationsListPresenter.(AuthorizationsListPresenter.kt:54)
at com.mandarine.sai.features.authorizations.list.di.AuthorizationsListModule.providePresenter + 48(AuthorizationsListModule.java:48)
at com.mandarine.sai.features.authorizations.list.di.AuthorizationsListModule_ProvidePresenterFactory.providePresenter + 87(AuthorizationsListModule_ProvidePresenterFactory.java:87)
at com.mandarine.sai.features.authorizations.list.di.AuthorizationsListModule_ProvidePresenterFactory.get + 50(AuthorizationsListModule_ProvidePresenterFactory.java:50)
at com.mandarine.sai.features.authorizations.list.di.AuthorizationsListModule_ProvidePresenterFactory.get + 15(AuthorizationsListModule_ProvidePresenterFactory.java:15)
at dagger.internal.DoubleCheck.get + 47(DoubleCheck.java:47)
at com.mandarine.sai.app.di.DaggerAppComponent$AuthorizationsListComponentImpl.injectAuthorizationsListFragment + 382(DaggerAppComponent.java:382)
at com.mandarine.sai.app.di.DaggerAppComponent$AuthorizationsListComponentImpl.inject + 376(DaggerAppComponent.java:376)
at com.mandarine.sai.features.authorizations.list.AuthorizationsListFragment.injectDependencies + 211(AuthorizationsListFragment.java:211)
at com.mandarine.sai.features.authorizations.list.AuthorizationsListFragment.onCreate + 58(AuthorizationsListFragment.java:58)
at androidx.fragment.app.Fragment.performCreate + 2414(Fragment.java:2414)
at androidx.fragment.app.FragmentManagerImpl.moveToState + 1418(FragmentManagerImpl.java:1418)
at androidx.fragment.app.FragmentManagerImpl.moveFragmentToExpectedState + 1784(FragmentManagerImpl.java:1784)
at androidx.fragment.app.FragmentManagerImpl.moveToState + 1852(FragmentManagerImpl.java:1852)
at androidx.fragment.app.FragmentManagerImpl.dispatchStateChange + 3269(FragmentManagerImpl.java:3269)
at androidx.fragment.app.FragmentManagerImpl.dispatchCreate + 3223(FragmentManagerImpl.java:3223)
at androidx.fragment.app.FragmentController.dispatchCreate + 190(FragmentController.java:190)
at androidx.fragment.app.FragmentActivity.onCreate + 369(FragmentActivity.java:369)
at androidx.appcompat.app.AppCompatActivity.onCreate + 85(AppCompatActivity.java:85)
at com.mandarine.sai.features.main.MainActivity.onCreate + 58(MainActivity.java:58)
at android.app.Activity.performCreate + 7084(Activity.java:7084)
at android.app.Activity.performCreate + 7075(Activity.java:7075)
at android.app.Instrumentation.callActivityOnCreate + 1215(Instrumentation.java:1215)
at android.app.ActivityThread.performLaunchActivity + 2767(ActivityThread.java:2767)
at android.app.ActivityThread.handleLaunchActivity + 2892(ActivityThread.java:2892)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage + 1613(ActivityThread.java:1613)
at android.os.Handler.dispatchMessage + 106(Handler.java:106)
at android.os.Looper.loop + 176(Looper.java:176)
at android.app.ActivityThread.main + 6635(ActivityThread.java:6635)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run + 547(RuntimeInit.java:547)
at com.android.internal.os.ZygoteInit.main + 823(ZygoteInit.java:823)
这是我在MainActivity中的代码:
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
if (!RealmManager.initialized) RealmManager.initRealm(context = this)
this.updateScreenshotLocking()
setContentView(R.layout.activity_main)
setupViews()
presenter.setInitialData(intent)
if (savedInstanceState == null) {
presenter.launchInitialFragment()
}
}