Home > other >  Getting the viewmodel in my fragment using 'by viewModels()' is displaying an error
Getting the viewmodel in my fragment using 'by viewModels()' is displaying an error

Time:11-06

When trying to get a reference to the viewModel from the fragment, I get the following error: "Type 'Lazy<TypeVariable(VM)>' has no method 'getValue(LoginTabFragment, KProperty<*>)' and thus it cannot serve as a delegate". The following image is of my fragment:fragment class

CodePudding user response:

Check if your LoginViewModel class is extending the ViewModel or not.

CodePudding user response:

Make sure that you have already added this dependency to your gradle

    implementation "androidx.fragment:fragment-ktx:$fragment_version"

and according to this the current stable version is 1.3.6

  • Related