Serious problems with Chapter 27 Code

Help Please:
I followed every word of the book till chapter 27, by the end of it I got these errors:

  1. ViewModel class cannot be instantiated so I used ViewModelFactory and it was resolved.

  2. But I can’t figure this one out:
    java.lang.NullPointerException: Attempt to invoke virtual method ‘android.content.SharedPreferences android.content.Context.getSharedPreferences(java.lang.String, int)’ on a null object reference

I’m using Android 4.0.2, Gradle 4.0.2, Min SDK 21