koin: Android using sharedviewmodel causes app crash
I am using - implementation "org.koin:koin-androidx-viewmodel:2.1.0" in my project.
In my modules, I declare it as -
private val viewModelModules = module {
viewModel { MySharedViewModel(get()) }
}
I have a MainActivity who has bottom navigation bar with 3 tabs. On clicking each tab, fragment A or B or C is opened.
And in my fragment A, B, C I inject the viewModel as -
private val viewModel by sharedViewModel<MySharedViewModel>()
I get an exception like this and app crashes -
java.lang.RuntimeException: Unable to start activity ComponentInfo: org.koin.core.error.NoBeanDefFoundException: No definition found for class:'com.client.example.ui.MySharedViewModel'. Check your definitions!
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 21
@nikhil-thakkar I did the same way in MainActivity as you recommended and still the same problem 😦
org.koin.core.error.NoBeanDefFoundException: No definition found for class:'com.client.example.ui.MySharedViewModel'. Check your definitions!