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.

No definition found for class:'androidx.lifecycle.SavedStateHandle'

See original GitHub issue

I’m using new Koin version 2.2.1 and I’m getting runtime error in viewmodel where i’m using SavedStateHandle In previous version 2.1.6 all was fine. I used savedStateViewModel, now i’m getting crash after migration

all I did acording to article, maybe something are missed there? https://doc.insert-koin.io/#/koin-android/viewmodel?id=viewmodel-and-state-bundle

Caused by: org.koin.core.error.NoBeanDefFoundException: No definition found for class:'androidx.lifecycle.SavedStateHandle'. Check your definitions! at org.koin.core.scope.Scope.throwDefinitionNotFound(Scope.kt:282) at org.koin.core.scope.Scope.resolveInstance(Scope.kt:251) at org.koin.core.scope.Scope.get(Scope.kt:204) at com.grument.laika.di.DiManager$module$1$19.invoke(DiManager.kt:76) at com.grument.laika.di.DiManager$module$1$19.invoke(DiManager.kt:35) at org.koin.core.instance.InstanceFactory.create(InstanceFactory.kt:53) at org.koin.core.instance.FactoryInstanceFactory.get(FactoryInstanceFactory.kt:36)  at org.koin.core.registry.InstanceRegistry.resolveInstance$koin_core(InstanceRegistry.kt:103)  at org.koin.core.scope.Scope.resolveInstance(Scope.kt:236)  at org.koin.core.scope.Scope.get(Scope.kt:204)  at org.koin.androidx.viewmodel.factory.StateViewModelFactory.create(StateViewModelFactory.kt:21)  at androidx.lifecycle.AbstractSavedStateViewModelFactory.create(AbstractSavedStateViewModelFactory.java:69)  at androidx.lifecycle.ViewModelProvider.get(ViewModelProvider.java:185)  at androidx.lifecycle.ViewModelProvider.get(ViewModelProvider.java:150)  at org.koin.androidx.viewmodel.ViewModelResolverKt.get(ViewModelResolver.kt:23)  at org.koin.androidx.viewmodel.ViewModelResolverKt.resolveInstance(ViewModelResolver.kt:12)  at org.koin.androidx.viewmodel.scope.ScopeExtKt.getViewModel(ScopeExt.kt:86)  at org.koin.androidx.viewmodel.scope.ScopeExtKt.getViewModel(ScopeExt.kt:72)  at org.koin.androidx.viewmodel.koin.KoinExtKt.getViewModel(KoinExt.kt:41)  at org.koin.androidx.viewmodel.ext.android.FragmentExtKt.getViewModel(FragmentExt.kt:71)  at com.grument.laika.view.transfer.StyleTransferFragment$$special$$inlined$viewModel$2.invoke(FragmentExt.kt:73)  at com.grument.laika.view.transfer.StyleTransferFragment$$special$$inlined$viewModel$2.invoke(Unknown Source:0)  at kotlin.UnsafeLazyImpl.getValue(Lazy.kt:81)  at com.grument.laika.view.transfer.StyleTransferFragment.getViewModel(Unknown Source:2)  at com.grument.laika.view.transfer.StyleTransferFragment.initObservers(StyleTransferFragment.kt:101)  at com.grument.laika.view.transfer.StyleTransferFragment.onViewCreated(StyleTransferFragment.kt:42)  at androidx.fragment.app.FragmentStateManager.createView(FragmentStateManager.java:332)  at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1199)  at androidx.fragment.app.FragmentManager.addAddedFragments(FragmentManager.java:2236)  at androidx.fragment.app.FragmentManager.executeOpsTogether(FragmentManager.java:2009)  at androidx.fragment.app.FragmentManager.removeRedundantOperationsAndExecute(FragmentManager.java:1965)  at androidx.fragment.app.FragmentManager.execPendingActions(FragmentManager.java:1861)  at androidx.fragment.app.FragmentManager$4.run(FragmentManager.java:413)  at android.os.Handler.handleCallback(Handler.java:938)  at android.os.Handler.dispatchMessage(Handler.java:99)  at android.os.Looper.loop(Looper.java:223)  at android.app.ActivityThread.main(ActivityThread.java:7656)  at java.lang.reflect.Method.invoke(Native Method)  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947) 

in module viewModel { (image: File) -> StyleTransferViewModel(context = androidContext(), repository = get(), modelManager = get(), state = get(), image = image) }

the class where i’m injecting class StyleTransferViewModel(private val context: Context, private val repository: Repository, private val modelManager: ModelManager, state: SavedStateHandle, image: File) : CommonViewModel(repository)

in fragment private val viewModel: StyleTransferViewModel by viewModel{ parametersOf(args.image) }

Koin project used and used version (please complete the following information): [e.g]: koin-core version 2.2.1

Any help apreciated

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:4
  • Comments:34 (8 by maintainers)

github_iconTop GitHub Comments

7reactions
jsaumellbasetiscommented, Dec 30, 2020

I also get the Caused by: org.koin.core.error.NoBeanDefFoundException: No definition found for class:'androidx.lifecycle.SavedStateHandle'. Check your definitions!. In my case setting the handle as first parameter does not solve it.

And passing the parameters by name or by position does not fix it either.

5reactions
arctouch-andrecardosocommented, Feb 12, 2021

The documentation is also not clear that SavedStateHandle must be the first parameter

Read more comments on GitHub >

github_iconTop Results From Across the Web

Koin No definition found for class, but already declared
Im trying to implement a Permission Injection using Koin as my D.I however when i execute my ViewModel that requires the PermissionRepository i ......
Read more >
SavedStateHandle - Android Developers
Returns a androidx.lifecycle.LiveData that access data associated with the given key. Parameters. @NonNull String key.
Read more >
Koin Android 3.3.0 - Easier, Better, Stronger with ViewModels
ViewModel is in touch with many topics like Lifecycle, SavedStateHandle, LiveData, Flow and other Android components.
Read more >
Android ViewModel & Navigation | Koin
lifecycle.ViewModel class. You can specify how you inject the constructor of the class and use the get() function to inject dependencies.
Read more >
SavedStateHandle.getLiveData(String key, T initialValue ...
Artifact used: androidx.lifecycle:lifecycle-viewmodel-savedstate:2.2.0. The backing map is only populated when MutableLiveData.setValue() is called.
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