Home:ALL Converter>Koin: getting NoBeanDefFoundException while resolving class instance in Java Activity

Koin: getting NoBeanDefFoundException while resolving class instance in Java Activity

Ask Time:2022-10-06T02:20:47         Author:Konstantin Konopko

Json Formatter

Using Koin3 for Java project. Currently I have to inject/get Koin instances in some Java Activities. But when I'm trying start an Activity with Koin injection, I get the following error: org.koin.core.error.NoBeanDefFoundException: No definition found for class [class_name]. Check your definitions!. Any suggestions?

Usign the same injections in Kotlin ViewModel class works good as expected.

Application:

KoinApplication koin = KoinAndroidApplication
        .create(this)
        .logger(new AndroidLogger())
        .modules(KoinModuleKt.getAppModule());
startKoin(koin);

Module:

val appModule = module {
    //singletons
    single <SettingsManagerInterface> { SettingsManager(androidContext()) }
    //factories
    factory <SystemServiceHelperInterface> { SystemServiceHelper(androidContext()) }
    viewModel { SettingsViewModel(get(), get()) }
}

Activity:

import static org.koin.java.KoinJavaComponent.get;

    public class LoginActivity extends AppCompatActivity {
        private final SettingsManagerInterface settingsManager = get(SettingsManager.class);
        private final SystemServiceHelperInterface serviceHelper = get(SystemServiceHelper.class);

Author:Konstantin Konopko,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/73964701/koin-getting-nobeandeffoundexception-while-resolving-class-instance-in-java-act
yy