koin: Can't getByClass ViewModel from ViewModelFactory with empty parameters
Describe the bug
I’m getting
Fatal Exception: java.lang.IllegalStateException
from
org.koin.androidx.viewmodel.ViewModelFactory.create (ViewModelFactory.kt:44)
that says
Can't getByClass ViewModel from ViewModelFactory with empty parameters
when i do
class CoilFragment : BaseFragment(){
private lateinit var binding: FragmentCoilBinding
private val viewModel: CoilViewModel by viewModel()
...
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?): View? {
binding = FragmentCoilBinding.inflate(inflater, container, false)
binding.fragment = this
binding.viewModel = viewModel // <-- It throws here
}
}
class CoilViewModel(val sharedPreferences: SharedPreferences) : ViewModel(){
// nothing special here
}
Koin project used and used version (please complete the following information):
koin_version = "1.0.0"
implementation "org.koin:koin-android:$koin_version"
implementation "org.koin:koin-androidx-scope:$koin_version"
implementation "org.koin:koin-androidx-viewmodel:$koin_version"
Additional moduleDefinition
val global = module {
single { PreferenceManager.getDefaultSharedPreferences(get()) as SharedPreferences }
}
val coilModule = module {
viewModel { CoilViewModel(get()) }
}
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 1
- Comments: 18 (7 by maintainers)
Don’t worry, I’m on it. 👍
Fixed in
1.0.1👍Can you try with
1.0.1-alpha-1? (just published a fix)Same issue here:
It happens in 1 of 10 cases. Good luck with fixing. And thanks for your work man, its excelent
It looks like everything works now. Thank you.
Just starting testing 1.0.1-alpha-1 in our team. We will let you know, whether the problem is solved or not. Thanks
The problem is that I can’t reproduce this crash. I can only see it via Firebase Crashlytisc. I found that it happens also in different places in my code.
It happens only to 0.01% of my users, but still.
I’m not sure what you meant by
something like that ?