Android using sharedviewmodel causes app crash
See original GitHub issueI 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!
Issue Analytics
- State:
- Created 4 years ago
- Comments:21
Top Results From Across the Web
Creating a ViewModel causes the app to crash. (Kotlin ...
I have been following a tutorial from Geeks for Geeks on how to make a simple note app for Android. I've practically copied...
Read more >App Failures by Koin: Story 3 — Issue With sharedViewModel()
This story highlights sharing data between Fragments via ViewModels, usage of sharedViewModel injection by Koin. As a true lover of Koin DI ...
Read more >Kotlin and Android From Scratch Flashcards | Quizlet
Android studio kotlin beginner study guide Learn with flashcards, games, and more — for free.
Read more >Android: you're probably leaking ViewModel and might not ...
Having too much memory leaks can make the app deplete close to or all of its memory, which could lead to: Lags: with...
Read more >Shared ViewModel Across Fragments - Android Developers
Use the Jetpack Navigation component within a more advanced app example and learn about the advantages of having a shared ViewModel across ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@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!
Did you mention
MyApp
in yourAndroidManifest.xml
? I don’t see any other options as to why this shouldn’t work. Maybe a github sample would help.