I'm trying to build an app with the following architecture: LoginActivity -> MainActivity -> everything else handled in fragments hosted by MainActivity. I'm also using the Kodein Framework for the first time and get the following error in my starting fragment:
Property delegate must have a 'provideDelegate(HomeFragment, KProperty*>' method. None of the following functions is suitable. provideDelegate(Context [highlighted in red], KProperty<>?) defined in org.kodein.di.android.KodeinPropertyDelegateProvider Type 'KodeinPropertyDelegateProvider' has no method 'getValue(HomeFragment, KProperty<>)' and thus it cannot serve as a delegate
This is my code so far:
class HomeFragment : Fragment(), KodeinAware {
override val kodein by kodein()
private val factory : MainViewModelFactory by instance()
private lateinit var viewModel: MainViewModel
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
// Inflate the layout for this fragment
val binding : FragmentHomeBinding = FragmentHomeBinding.inflate(inflater, container, false)
viewModel = ViewModelProviders.of(this, factory).get(MainViewModel::class.java)
binding.viewModel = viewModel
return binding.root
}
}
How can I fix this?
Thanks :)
Nevermind, adding a type declaration after kodein did the trick... :)