title: Cannot create an instance of viewmodel class with hilt
body: <p>I am trying to create MVVM app using Openweathermap API and hilt. I tried to inject my repository into my viewmodel primary constractor and creating a ViewModelFactory class, in order to pass the parameters from viewmodel class to my main activity class it did not work with 'by viewmodels()' itself. Sadly it did not work and I am getting the following message &quot;has no zero argument constructor&quot;. It worth to mention that I also tried to inject the repository into my secondary constractor.</p>
  <p><strong>This is my MainActivity</strong></p>
  <pre><code>@AndroidEntryPoint
  class MainActivity
      @Inject constructor(var repository:WeatherRepositoryInterface) : AppCompatActivity() {
      private lateinit var binding: ActivityMainBinding
      private lateinit var previewAdapter: PreviewAdapter
      lateinit var viewModel:WeatherViewModel
      override fun onCreate(savedInstanceState: Bundle?) {
          super.onCreate(savedInstanceState)
          binding = ActivityMainBinding.inflate(layoutInflater)
          setContentView(binding.root)
          initViewItems()
      }
  
      fun initViewItems() {
         viewModel= ViewModelProvider(this@MainActivity,FactoryViewModel(application,repository))[WeatherViewModel::class.java]
          binding.recyclerview.apply {
              layoutManager = LinearLayoutManager(this@MainActivity)
              previewAdapter = PreviewAdapter(viewModel.loadCities().value!!)
              previewAdapter.let {
                  it.setOnItemClickListener(object: OnClickInterface{
                      override fun onClickItem(position: Int) {
                    var intent=Intent(this@MainActivity,DetailActivity::class.java)
                          intent.putExtra(&quot;name&quot;,viewModel.loadCities().value!![position].cityName)
                          intent.putExtra(&quot;img&quot;,viewModel.loadCities().value!![position].cityImg)
                          startActivity(intent)
                      }
                  })
              }
              adapter = previewAdapter
       }
      }
  }
  </code></pre>
  <p><strong>My ViewModel class</strong></p>
  <pre><code>@HiltViewModel
  class WeatherViewModel @Inject constructor(application: Application, var repository: WeatherRepositoryInterface)
   : AndroidViewModel(application) ,LifecycleObserver{
  companion object{
    private  val VIEWMODEL_STRING=&quot;WeatherViewModel.class&quot;
  }
  private var list: MutableLiveData&lt;List&lt;Preview&gt;&gt; = MutableLiveData()
   fun getCityInfo(q:String) =
       liveData(Dispatchers.IO){
    emit(com.example.yourweatherapp.Resources.Resource.loading(data = null))
    try {
    emit(com.example.yourweatherapp.Resources.Resource.success(data = repository.getWeather(q=q)))
    } catch (e: Exception) {
     emit(e.message?.let { com.example.yourweatherapp.Resources.Resource.error(data = null, message = it) })
        e.message?.let { Log.e(VIEWMODEL_STRING, it) }
    }
   }
  
   fun loadCities():MutableLiveData&lt;List&lt;Preview&gt;&gt;{
    list.value= listOf(
  Preview(
   CityList.santorini,
   CityList.santoriniImg),
  Preview(CityList.bern,
  CityList.bernImg),
  Preview(CityList.venice,
  CityList.veniceImg),
  Preview(&quot;&quot;,CityList.myLocationImg)
    )
    return list
   }
  }
  </code></pre>
  <p><strong>My ViewModelFactory class:</strong></p>
  <pre><code>class FactoryViewModel(
      var application:Application,
      var repository: WeatherRepositoryInterface
  ): ViewModelProvider.NewInstanceFactory() {
  
      override fun &lt;T : ViewModel&gt; create(modelClass: Class&lt;T&gt;): T =
          WeatherViewModel(application,repository) as T
  }
  </code></pre>
  <p><strong>My Gradle dependency file:</strong></p>
  <pre><code>plugins {
     id 'com.android.application'
     id 'org.jetbrains.kotlin.android'
     id 'kotlin-kapt'
  
  
  }
  
  android {
     compileSdk 31
  
     defaultConfig {
         applicationId &quot;com.example.yourweatherapp&quot;
         minSdk 21
         targetSdk 31
         versionCode 1
         versionName &quot;1.0&quot;
  
         testInstrumentationRunner &quot;androidx.test.runner.AndroidJUnitRunner&quot;
     }
  
     buildFeatures {
         dataBinding = true
         viewBinding = true
     }
     buildTypes {
         release {
             minifyEnabled false
             proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
         }
     }
     compileOptions {
         sourceCompatibility JavaVersion.VERSION_1_8
         targetCompatibility JavaVersion.VERSION_1_8
     }
     kotlinOptions {
         jvmTarget = '1.8'
     }
  }
  
  dependencies {
  
     implementation 'androidx.core:core-ktx:1.7.0'
     implementation 'androidx.appcompat:appcompat:1.4.0'
     implementation 'com.google.android.material:material:1.4.0'
     implementation 'androidx.constraintlayout:constraintlayout:2.1.2'
     implementation 'androidx.navigation:navigation-fragment-ktx:2.4.0'
     implementation 'androidx.navigation:navigation-ui-ktx:2.4.0'
     testImplementation 'junit:junit:4.13.2'
     androidTestImplementation 'androidx.test.ext:junit:1.1.3'
     androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
     implementation &quot;com.squareup.retrofit2:converter-gson:2.9.0&quot;
     implementation &quot;com.squareup.retrofit2:retrofit:2.9.0&quot;
     implementation(&quot;androidx.cardview:cardview:1.0.0&quot;)
     implementation 'com.github.bumptech.glide:glide:4.12.0'
     implementation(&quot;androidx.cardview:cardview:1.0.0&quot;)
     implementation(&quot;androidx.recyclerview:recyclerview:1.2.1&quot;)
   //  implementation (&quot;androidx.lifecycle:lifecycle-livedata:2.5.0-alpha01&quot;)
  
  //http3
     implementation(platform(&quot;com.squareup.okhttp3:okhttp-bom:4.9.3&quot;))
     implementation &quot;androidx.lifecycle:lifecycle-runtime-ktx:2.5.0-alpha01&quot;
     implementation &quot;androidx.activity:activity-ktx:1.1.0&quot;
     implementation(&quot;com.squareup.okhttp3:okhttp&quot;)
     implementation(&quot;com.squareup.okhttp3:logging-interceptor&quot;)
  
  //lifecycle
     implementation &quot;androidx.lifecycle:lifecycle-livedata-ktx:2.4.0&quot;
  
     implementation(&quot;androidx.lifecycle:lifecycle-viewmodel-ktx:2.4.0&quot;)
     implementation(&quot;androidx.lifecycle:lifecycle-viewmodel-compose:2.4.0&quot;)
  
  
     kapt(&quot;androidx.lifecycle:lifecycle-compiler:2.5.0-alpha01&quot;)
     implementation(&quot;androidx.lifecycle:lifecycle-common-java8:2.5.0-alpha01&quot;)
     implementation(&quot;androidx.lifecycle:lifecycle-service:2.5.0-alpha01&quot;)
     
  
    //fragment
     implementation(&quot;androidx.fragment:fragment-ktx:1.4.1&quot;)
     implementation(&quot;androidx.navigation:navigation-fragment-ktx:2.4.1&quot;)
     implementation(&quot;androidx.navigation:navigation-ui-ktx:2.4.1&quot;)
  
  
     //hilt dagger
     implementation(&quot;com.google.dagger:hilt-android:2.38.1&quot;)
     kapt(&quot;com.google.dagger:hilt-android-compiler:2.38.1&quot;)
     //implementation &quot;org.jetbrains.kotlinx:kotlinx-coroutines-android:1.4.2&quot;
   implementation 'androidx.hilt:hilt-navigation-compose:1.0.0'
   implementation 'androidx.hilt:hilt-navigation-compose:1.0.0'
     implementation 'androidx.hilt:hilt-lifecycle-viewmodel:1.0.0-alpha03'
     kapt 'androidx.hilt:hilt-compiler:1.0.0'
  
  
  }
  
  kapt {
     javacOptions {
         // These options are normally set automatically via the Hilt Gradle plugin, but we
         // set them manually to workaround a bug in the Kotlin 1.5.20
         option(&quot;-Adagger.fastInit=ENABLED&quot;)
         option(&quot;-Adagger.hilt.android.internal.disableAndroidSuperclassValidation=true&quot;)
     }
  }
  </code></pre>