title: Cannot create an instance of class ViewModel
body: <p>I am trying to write a sample app using Android architecture components and but even after trying for days I could not get it to work. It gives me the above exception.</p>
  
  <p>Lifecycle owner:-</p>
  
  <pre><code>public class MainActivity extends LifecycleActivity {
  
      public void onCreate(Bundle savedInstanceState)
      {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
          TextView textView = findViewById(R.id.tv_user);
          PostViewModel viewModel = ViewModelProviders.of(this).get(PostViewModel.class);
          viewModel.loadPosts();
          viewModel.getPost().observe(this, new Observer&lt;Post&gt;() {
              @Override
              public void onChanged(@Nullable Post post) {
                  if(post != null) {
                      textView.setText(post.toString());
                  }
              }
          });
      }
  }
  </code></pre>
  
  <p>ViewModel:-</p>
  
  <pre><code>public class PostViewModel extends ViewModel {
      private MediatorLiveData&lt;Post&gt; post;
      private PostRepository postRepo;
  
      PostViewModel() {
          post = new MediatorLiveData&lt;&gt;();
          postRepo = new PostRepository();
      }
  
      public LiveData&lt;Post&gt; loadPosts() {
          post.addSource(postRepo.getPost(),
                  post -&gt; this.post.setValue(post)
          );
          return post;
      }
  
      @NonNull
      public LiveData&lt;Post&gt; getPost() {
          return post;
      }
  }
  </code></pre>