title: Cannot create an instance of ViewModel class (Unable to start activity ComponentInfo)
body: <p>I am using MVVM, Retrofit, LiveData in my project but I get this error before that I saw these links</p>
  <ul>
  <li><a href="https://stackoverflow.com/q/45459917/5528079">Cannot create an instance of custom ViewModel</a></li>
  <li><a href="https://stackoverflow.com/q/44998051/5528079">Cannot create an instance of class ViewModel</a></li>
  </ul>
  <h2>Error</h2>
  <pre><code>java.lang.RuntimeException:       
  Unable to start activity ComponentInfo{ir.orangehat.movieinfo/ir.orangehat.movieinfo.application.home.HomeActivity}: java.lang.RuntimeException:
  
  Cannot create an instance of class ir.orangehat.movieinfo.application.home.HomeViewModel
                    
  </code></pre>
  <h2>ViewModel</h2>
  <p>I think the problem is in my constructor</p>
  <pre><code>public class HomeViewModel extends AndroidViewModel {
  
  private MovieRepository movieRepository;
  
  public HomeViewModel(@NonNull Application application, Context context, LifecycleOwner lifecycleOwner) {
      super(application);
      movieRepository = new MovieRepository(lifecycleOwner, context);
  }
  
  LiveData&lt;List&lt;Movie&gt;&gt; getMovies() {
      return movieRepository.getMovies();
  }}
  </code></pre>
  <h2>Repository</h2>
  <pre><code>public class MovieRepository extends BaseRepository {
  
  private LifecycleOwner lifecycleOwner;
  private MovieApi movieApi;
  private MovieDatabaseHelper movieDatabaseHelper;
  
  public MovieRepository(LifecycleOwner lifecycleOwner, Context context) {
      this.lifecycleOwner = lifecycleOwner;
      movieApi = getRetrofitHelper().getService(MovieApi.class);
      movieDatabaseHelper = new MovieDatabaseHelper(context);
  }
  
  public LiveData&lt;List&lt;Movie&gt;&gt; getMovies() {
      LiveData&lt;List&lt;Movie&gt;&gt; moviesLiveData = movieApi.getMovieList();
      moviesLiveData.observe(lifecycleOwner, new Observer&lt;List&lt;Movie&gt;&gt;() {
          @Override
          public void onChanged(@Nullable List&lt;Movie&gt; movieArrayList) {
              movieDatabaseHelper.Save(movieArrayList);
          }
      });
  
      return movieDatabaseHelper.getAll();
  } }
  </code></pre>
  <h2>Activity class</h2>
  <pre><code>public class HomeActivity extends AppCompatActivity {
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          // the error is here
          HomeViewModel homeViewModel = ViewModelProviders.of(this).get(HomeViewModel.class);
  
          homeViewModel.getMovies().observe(HomeActivity.this, new Observer&lt;List&lt;Movie&gt;&gt;() {
              @Override
              public void onChanged(@Nullable List&lt;Movie&gt; movieArrayList) {
                  String str = null;
                  if (movieArrayList != null) {
                      str = Arrays.toString(movieArrayList.toArray());
                  }
                  Log.e(&quot;movies&quot;, str);
              }
          });
      }
  }
  </code></pre>
  <p>Should I use Dagger in my project and custom factory?</p>