title: java.lang.ClassCastException: com.eng.bt_eng_mobility.viewmodel.HomeViewModelFactory cannot be cast to androidx.lifecycle.ViewModel
body: <p>I am getting this error. I have created ViewModelFactory class inside same ViewModel class file.
  When Im trying to initialise the viewmodel I am getting this error.</p>
  <pre><code>//Code written in fragment class in onCreateView after binding code//
  homeViewModelFactory = HomeViewModelFactory((requireActivity().application as Application).repository)
          homeViewModel = ViewModelProvider(this, homeViewModelFactory)
                  .get(HomeViewModel::class.java)
  
  
  //Viewmodelfactoryclass//
  class HomeViewModelFactory(private val homeRepository: HomeRepository) : ViewModelProvider.Factory {
      override fun &lt;T : ViewModel&gt; create(modelClass: Class&lt;T&gt;): T {
          if (modelClass.isAssignableFrom(HomeViewModel::class.java)) {
              return HomeViewModelFactory(homeRepository) as T
          }
          throw IllegalArgumentException(&quot;Unknown ViewModel class&quot;)
      }
  }
  
  
  </code></pre>