question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Android using sharedviewmodel causes app crash

See original GitHub issue

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!

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:21

github_iconTop GitHub Comments

1reaction
vivekwolf123commented, Feb 29, 2020

@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!

0reactions
nikhil-thakkarcommented, Feb 29, 2020

Did you mention MyApp in your AndroidManifest.xml? I don’t see any other options as to why this shouldn’t work. Maybe a github sample would help.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found