【问题标题】:java.lang.IllegalStateException: KoinApplication has not been startedjava.lang.IllegalStateException: KoinApplication 尚未启动
【发布时间】:2020-04-28 16:02:07
【问题描述】:

我正在使用 koin 学习 kotlin。在 catlog 中运行应用程序时,我看到以下消息。

java.lang.IllegalStateException: KoinApplication 尚未启动

虽然我在 MyApplication 中使用过 startKoin

class MyApplication : Application() {

    var listOfModules = module {
        single { GitHubServiceApi() }
    }

    override fun onCreate() {
        super.onCreate()

        startKoin {
            androidLogger()
            androidContext(this@MyApplication)
            modules(listOfModules)
        }

    }

} 

我发现了我做错的问题。我想在 mainfest.xml 中添加 MyApplcation 名称

【问题讨论】:

  • 找到我做错的地方。谢谢大家
  • 你的新错误是什么?请详细解释一下
  • 我只有一个设备有这个问题? c
  • 我只在我的 Galaxy s10 上遇到这个问题:l

标签: kotlin koin


【解决方案1】:

在 Manifest 文件中添加 "android:name=".TheApplication" 解决了这个问题。

    android:name=".TheApplication"
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_app_icon_round"
    android:supportsRtl="true"
    android:theme="@style/Theme.Shrine">
    <activity android:name=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

"android:name=".TheApplication" 是来自 Koin 的类名

class TheApplication : Application() {

    override fun onCreate() {
        super.onCreate()

        if (BuildConfig.DEBUG) {
            Timber.plant(Timber.DebugTree())
        }

        startKoin {
            androidLogger()
            androidContext(androidContext = this@TheApplication)

            modules(
                listOfModules
            )
        }
    }
}

【讨论】:

    【解决方案2】:

    基本上,您需要在 Manifest 中将调用 startKoin() 方法的类的名称作为应用程序名称。这将让您配置日志记录、属性加载和模块。看看这个:https://doc.insert-koin.io/#/koin-core/dsl

    【讨论】:

      猜你喜欢
      • 2020-04-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-05-13
      • 2021-08-17
      相关资源
      最近更新 更多