title: Android LiveData, Cannot create an instance of class viewModel
body: <p>Following the example given by <a href="https://developer.android.com/topic/libraries/architecture/livedata" rel="nofollow noreferrer">android</a>, I extended the ViewModel class </p>
  
  <pre><code>public class NameViewModel extends ViewModel {
  private MutableLiveData&lt;String&gt; currentName;
  
  public MutableLiveData&lt;String&gt; getCurrentName() {
      if (currentName == null) {
          currentName = new MutableLiveData&lt;String&gt;();
      }
      return currentName;
  }}
  </code></pre>
  
  <p>and i observed the LiveData objects</p>
  
  <pre><code>public class NameActivity extends AppCompatActivity {
  
  private NameViewModel model;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
  
      // Other code to setup the activity...
  
      // Get the ViewModel.
      model = new ViewModelProvider(this).get(NameViewModel.class);
  
      // Create the observer which updates the UI.
      final Observer&lt;String&gt; nameObserver = new Observer&lt;String&gt;() {
          @Override
          public void onChanged(@Nullable final String newName) {
              // Update the UI, in this case, a TextView.
              nameTextView.setText(newName);
          }
      };
  
      // Observe the LiveData, passing in this activity as the LifecycleOwner and the observer.
      model.getCurrentName().observe(this, nameObserver);
  }}
  </code></pre>
  
  <p>and my dependencies in build.gradle are</p>
  
  <pre><code>dependencies {
      def lifecycle_version = "2.2.0"
  
      implementation fileTree(dir: 'libs', include: ['*.jar'])
  
      implementation 'androidx.appcompat:appcompat:1.0.2'
      implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
  
      // ViewModel
      implementation "androidx.lifecycle:lifecycle-viewmodel:$lifecycle_version"
      // LiveData
      implementation "androidx.lifecycle:lifecycle-livedata:$lifecycle_version"
      // Lifecycles only (without ViewModel or LiveData)
      implementation "androidx.lifecycle:lifecycle-runtime:$lifecycle_version"
  
  
      testImplementation 'junit:junit:4.12'
      androidTestImplementation 'androidx.test.ext:junit:1.1.1'
      androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
  }
  </code></pre>
  
  <p>Running this code is giving Cannot create an instance of class NameViewModel, what am I doing wrong in here?</p>