I have been spending a lot of time trying to figure out why in the code below (towards the end), I get an error on ViewModelProvider(this). I also tried getActivity() instead of
You aren't using the latest library release in which the ViewModelProvider(@NonNull ViewModelStoreOwner owner)
constructor was included. You are seeing the latest docs but not using the latest library version of ViewModel
.
You need to use
implementation 'androidx.lifecycle:lifecycle-viewmodel:2.2.0' // For Java
or
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0' // For kotlin extension