I’ve added the android name in the manifest and no...
# koin
s
I’ve added the android name in the manifest and now getting errors that
Unable to start activity ComponentInfo{com.example.cakesapimvvm/com.example.cakesapimvvm.MainActivity}: org.koin.core.error.InstanceCreationException: Could not create instance for [Factory:'com.example.cakesapimvvm.viewmodel.CakeListViewModel']
j
Do you have the definition for
CakeListViewModel
in any of your modules?
s
Yes, so CakeListViewModel is a ViewModel that is passed in via dependancy injection
Copy code
class CakeListViewModel (private val cakeRepository: CakeRepository) : ViewModel() {
    private val viewModelJob = SupervisorJob()
    private val viewModelScope  = CoroutineScope(viewModelJob + Dispatchers.Main)

    val cakeListResults = cakeRepository.results

    init {
        refreshFromRepository()
    }

    fun refreshFromRepository(){
        viewModelScope.launch {
            try {
                cakeRepository.refreshCakes()
            }
            catch(networkError: Exception){

            }
        }
    }

    override fun onCleared() {
        super.onCleared()
        viewModelScope.cancel()
    }
}
f
is your CakeListViewModel defined properly in your viewModelModule ?
j
show you (koin) module definition where this ViewModel is instantiated
s
Copy code
import com.example.cakesapimvvm.viewmodel.CakeListViewModel
import org.koin.android.viewmodel.dsl.viewModel
import org.koin.dsl.module

val viewModelModule= module {
    viewModel { CakeListViewModel(get()) }
}
Still not solved this. Error is located where I comment binding.viewmodel = viewmodel and becomes
Unable to get current module info in ModuleManager created with non-module Context
j
And are you injecting that module? So it seems like at runtime koin can’t find a definition of your viewmodel — So in other words, doesn’t know how to create it
s
Any thoughts how to create it?