title: AndroidViewModel has no zero argument constructor
body: <p>I am trying to create an instance of my AndroidViewModel in MainActivity. When I do this I get the following error <strong>has no zero argument constructor</strong></p>
  
  <p>Here is my RecipeViewModel</p>
  
  <pre><code>package com.example.kookrecepten;
  
  import android.app.Application;
  
  import androidx.lifecycle.AndroidViewModel;
  import androidx.lifecycle.LiveData;
  
  import java.util.List;
  
  public class RecipeViewModel extends AndroidViewModel {
      private RecipeRepository recipeRepository;
      private LiveData&lt;List&lt;Recipe&gt;&gt; allRecipes;
  
      public RecipeViewModel(Application application) {
          super(application);
          recipeRepository = new RecipeRepository(application);
          allRecipes = recipeRepository.getAllRecipes();
      }
  
      public void insert(Recipe recipe) {
          recipeRepository.insert(recipe);
      }
  
      public void update(Recipe recipe) {
          recipeRepository.update(recipe);
      }
  
      public void delete(Recipe recipe) {
          recipeRepository.delete(recipe);
      }
  
      public void deleteAll() {
          recipeRepository.deleteAllRecipes();
      }
  
      public LiveData&lt;List&lt;Recipe&gt;&gt; getAllRecipes() {
          return allRecipes;
      }
  }
  </code></pre>
  
  <p>Now correct me if I'm wrong but AndroidViewModel needs the Application context in the constructor and ViewModel doesn't. So I have no idea why android asks for a zero arguments constructor.</p>
  
  <p>Here is my Main activity where I ask for an instance.</p>
  
  <pre><code>package com.example.kookrecepten;
  
  import android.os.Bundle;
  import android.view.View;
  import android.widget.Toast;
  
  import androidx.appcompat.app.AppCompatActivity;
  import androidx.lifecycle.Observer;
  import androidx.lifecycle.ViewModelProvider;
  
  import com.example.kookrecepten.databinding.ActivityMainBinding;
  
  import java.util.List;
  
  
  public class MainActivity extends AppCompatActivity {
      private ActivityMainBinding binding;
      private RecipeViewModel recipeViewModel;
  
      protected void onCreate (Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          binding = ActivityMainBinding.inflate(getLayoutInflater());
          View view = binding.getRoot();
          setContentView(view);
  
          //Get an instance of the RecipeViewModel.
          recipeViewModel = new ViewModelProvider(this).get(RecipeViewModel.class);
          recipeViewModel.getAllRecipes().observe(this, new Observer&lt;List&lt;Recipe&gt;&gt;() {
              @Override
              public void onChanged(List&lt;Recipe&gt; recipes) {
                  //Update recycle view
  
                  Toast.makeText(MainActivity.this, "triggered", Toast.LENGTH_SHORT).show();
              }
          });
      }
  }
  
  </code></pre>
  
  <p>And this are my implementations.</p>
  
  <pre><code>def lifecycle_version = "2.2.0"
  def room_version = "2.2.5"
  
  //LifeCycle Components
      // ViewModel
      implementation "androidx.lifecycle:lifecycle-viewmodel:$lifecycle_version"
      // LiveData
      implementation "androidx.lifecycle:lifecycle-livedata:$lifecycle_version"
      // Annotation processor
      implementation "androidx.lifecycle:lifecycle-common-java8:$lifecycle_version"
  
      //Room Components
      implementation "androidx.room:room-runtime:$room_version"
      annotationProcessor "androidx.room:room-compiler:$room_version"
  </code></pre>