You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When a shared ViewModel that has parameters gets injected in a Fragment, Koin fails to retrieve the instance:
Caused by org.koin.core.error.InstanceCreationException: Could not create instance for '[Factory:'hm.a']'
at org.koin.core.error.InstanceCreationException.<init>(InstanceCreationException.java:23)
at org.koin.core.instance.InstanceFactory.create(InstanceFactory.kt:57)
at org.koin.core.instance.FactoryInstanceFactory.get(FactoryInstanceFactory.kt:38)
at org.koin.core.registry.InstanceRegistry.resolveInstance$koin_core(InstanceRegistry.java:109)
at org.koin.core.scope.Scope.resolveValue(Scope.kt:247)
at org.koin.core.scope.Scope.resolveInstance(Scope.kt:233)
at org.koin.core.scope.Scope.get(Scope.kt:212)
at org.koin.androidx.viewmodel.factory.KoinViewModelFactory.create(KoinViewModelFactory.kt:25)
at androidx.lifecycle.ViewModelProvider.get(ViewModelProvider.kt:184)
at androidx.lifecycle.ViewModelProvider.get(ViewModelProvider.kt:150)
at org.koin.androidx.viewmodel.GetViewModelKt.resolveViewModel(GetViewModel.kt:43)
at org.koin.androidx.viewmodel.GetViewModelKt.resolveViewModel$default(GetViewModel.kt:28)
Caused by org.koin.core.error.NoParameterFoundException: Can't get injected parameter #0 from DefinitionParameters[] for type 'xxx'
at org.koin.core.error.NoParameterFoundException.<init>(NoParameterFoundException.java:23)
at org.koin.core.parameter.ParametersHolder.elementAt(ParametersHolder.kt:45)
at org.koin.androidx.viewmodel.parameter.AndroidParametersHolder.access$elementAt$s975513686(AndroidParametersHolder.kt:10)
at org.koin.androidx.viewmodel.parameter.AndroidParametersHolder$elementAt$1.invoke(AndroidParametersHolder.kt:16)
at org.koin.androidx.viewmodel.parameter.AndroidParametersHolder.createSavedStateHandleOrElse(AndroidParametersHolder.kt:26)
at org.koin.androidx.viewmodel.parameter.AndroidParametersHolder.elementAt(AndroidParametersHolder.kt:16)
It seems to happen if the activity is implementing AndroidScopeComponent with activityRetainedScope() scope.
Koin module and version:
koin-android:3.5.3
koin-core:3.5.3
was working well on 3.5.0
Snippet or Sample project to help reproduce
// VMclassWeatherViewModel(privatevalid:Anything) : ViewModel()
// inside Koin module
viewModel<WeatherViewModel> { (
id:Anything
) ->WeatherViewModel(id)
}
scope<WeatherActivity> {
scoped<Anything> {
Anything()
}
}
// ActivityclassWeatherActivity : AppCompatActivity(), AndroidScopeComponent {
overrideval scope:Scope by activityRetainedScope()
privateval anything:Anything by inject()
privateval weatherViewModel by viewModel<WeatherViewModel> {
parametersOf(anything)
}
overridefunonCreate(savedInstanceState:Bundle?) {
super.onCreate(savedInstanceState)
weatherViewModel.run {}
// attach fragment
}
}
// Fragment instantiated by the activityclassWeatherListFragment : Fragment() {
privateval weatherViewModel by activityViewModel<WeatherViewModel>()
}
The text was updated successfully, but these errors were encountered:
fleficher
changed the title
activityViewModel with parameters can't be injected
activityViewModel with scoped parameters can't be injected
Mar 20, 2024
On Koin 3.5.6 I am getting the same error Caused by org.koin.core.error.NoParameterFoundException: Can't get injected parameter #0 from DefinitionParameters[] for type 'xxx'
and I am also using an Activity with AndroidScopeComponent but I am not using ViewModel and activityRetainedScope().
I could reproduce de error with this test on the Koin lib:
Describe the bug
When a shared ViewModel that has parameters gets injected in a Fragment, Koin fails to retrieve the instance:
It seems to happen if the activity is implementing
AndroidScopeComponent
withactivityRetainedScope()
scope.Koin module and version:
koin-android:3.5.3
koin-core:3.5.3
was working well on
3.5.0
Snippet or Sample project to help reproduce
The text was updated successfully, but these errors were encountered: