Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java.lang.IllegalStateException: KoinApplication has not been started

Tags:

kotlin

koin

I am learning kotlin using koin. While running the application in catlog I see the following message.

java.lang.IllegalStateException: KoinApplication has not been started

though I have used startKoin in MyApplication

class MyApplication : Application() {

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

    override fun onCreate() {
        super.onCreate()

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

    }

} 

enter image description here

I found the issue where I have done my mistake.I was suppose to add the MyApplcation name in mainfest.xml

enter image description here

like image 571
anandyn02 Avatar asked Jan 11 '20 02:01

anandyn02


2 Answers

Adding "android:name=".TheApplication" in the Manifest file solved the issue.

    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" is the Class Name from Koin

class TheApplication : Application() {

    override fun onCreate() {
        super.onCreate()

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

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

            modules(
                listOfModules
            )
        }
    }
}
like image 105
Leonard Avatar answered Oct 17 '22 00:10

Leonard


Basically, you need to give the name of the class where you called startKoin() method, in the Manifest as an application name. And this will let your configure logging, properties loading and modules. Check this out: https://doc.insert-koin.io/#/koin-core/dsl

like image 1
Xarybdis Avatar answered Oct 16 '22 23:10

Xarybdis