Type error on ViewModelProviders#of(Fragment)
Architecture Components uses the appcompat Fragment
from the support library rather than the native one. Try changing your import for Fragment
to
import android.support.v4.app.Fragment;
For historical reasons, there are two different Fragment
classes. They have the same functionality but exist in two different packages. For details, see Why are there two Fragment classes in Android?
As of Feb 6, 2019:
Now there is a third Fragment
class. If you are using the new AndroidX libraries, then do
import androidx.fragment.app.Fragment;
Be sure you use the correct Fragment
class which is consistent with the rest of your dependencies.
I have had the same problem, what the google documentation does not tell you is that you need to add the following dependencies in to your Build Gradle file and then "Sync"
implementation "android.arch.lifecycle:extensions:1.1.1"
annotationProcessor "android.arch.lifecycle:compiler:1.1.1"