面临的问题在 AppModule 中插入 ContentProvider。
我的应用级别模块是
module {
single { TinyDB.getInstance(get()) }
single { DataRepository(get()) }
viewModel { HomeViewModel(get()) }
}
我不知道如何在模块中使用 ContentProvider
我试过代码
val dataRepo = inject(DataRepository::class.java)
这在我的内容提供程序中,但在此之后我的应用程序开始崩溃并且 logcat 显示错误按摩
java.lang.RuntimeException: Unable to get provider wastickerapps.newemojistickers.stickersforwhatsapp.whatsappUsages.StickerContentProvider: java.lang.IllegalStateException: StandAloneContext Koin instance is null
at android.app.ActivityThread.installProvider(ActivityThread.java:5562)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:5154)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5094)
at android.app.ActivityThread.access$1600(ActivityThread.java:177)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1509)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:5942)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)
Caused by: java.lang.IllegalStateException: StandAloneContext Koin instance is null
at org.koin.standalone.StandAloneContext.getKoin(StandAloneContext.kt:68)
at org.koin.standalone.KoinComponentKt.getKoinContext(KoinComponent.kt:42)
at org.koin.standalone.KoinComponentKt.access$getKoinContext(KoinComponent.kt:1)
at org.koin.standalone.KoinComponent$DefaultImpls.getKoin(KoinComponent.kt:36)
at wastickerapps.newemojistickers.stickersforwhatsapp.whatsappUsages.StickerContentProvider.getKoin(StickerContentProvider.kt:27)
at wastickerapps.newemojistickers.stickersforwhatsapp.whatsappUsages.StickerContentProvider.<init>(StickerContentProvider.kt:481)
at java.lang.reflect.Constructor.newInstance(Native Method)
at java.lang.Class.newInstance(Class.java:1650)
at android.app.ActivityThread.installProvider(ActivityThread.java:5547)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:5154)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5094)
at android.app.ActivityThread.access$1600(ActivityThread.java:177)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1509)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:5942)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at