title: How to use ViewModelProviders in Kotlin
body: <p>I am new bie to Kotlin, Please help me how to use ViewModelProviders.of(this) in Kotlin </p>
  
  <p>My code in java is</p>
  
  <pre><code> mFavViewModel = ViewModelProviders.of(this).get(FavouritesViewModel.class);
  </code></pre>
  
  <p>I am not able to find <strong>ViewModelProviders</strong> class in kotlin
  tried auto convert but its showing errors.
  Thanks.</p>
  
  <p>Here is my DataModel class</p>
  
  <pre><code>class FavoritesDataViewModel:ViewModel{
      private var mFavHelper: DatabaseHelper
      private lateinit var mfav:ArrayList&lt;Favorites&gt;
       constructor(application: Application) {
          mFavHelper = DatabaseHelper(application)
      }
      fun getListFav():List&lt;Favorites&gt;{
          if (mfav==null){
              mfav =  arrayListOf&lt;Favorites&gt;()
              createDummyList()
              loadFav()
          }
          val clonedFavs = arrayListOf&lt;Favorites&gt;()
          for (i in 0 until mfav.size) {
              clonedFavs.add(Favorites(mfav.get(i)))
          }
          return clonedFavs
      }
      fun createDummyList(){
          addFav("https://www.journaldev.com", Date().getTime())
          addFav("https://www.medium.com", Date().getTime())
          addFav("https://www.reddit.com", Date().getTime())
          addFav("https://www.github.com", Date().getTime())
          addFav("https://www.hackerrank.com", Date().getTime())
          addFav("https://www.developers.android.com", Date().getTime())
  
      }
      fun addFav(url:String,date:Long):Favorites{
          val db:SQLiteDatabase = this.mFavHelper.getWritableDatabase();
          val values: ContentValues = ContentValues();
          values.put(DbSettings.DbEntry.COL_FAV_DATE,date)
          values.put(DbSettings.DbEntry.COL_FAV_URL,url)
          val id:Long = db.insertWithOnConflict(DbSettings.DbEntry.TABLE,
              null,
              values,SQLiteDatabase.CONFLICT_REPLACE)
          db.close()
          val fav:Favorites = Favorites(id,url,date)
          mfav.add(fav)
          return Favorites(fav)
      }
      fun loadFav(){
          mfav.clear()
          val db:SQLiteDatabase = mFavHelper.readableDatabase
          val cursor:Cursor = db.query(DbSettings.DbEntry.TABLE,
               arrayOf(
                  DbSettings.DbEntry._ID,
                  DbSettings.DbEntry.COL_FAV_URL,
                  DbSettings.DbEntry.COL_FAV_DATE
               ),
              null, null, null, null, null);
          while (cursor.moveToNext()){
              val idxID:Int = cursor.getColumnIndex(DbSettings.DbEntry._ID)
              val idxURL:Int = cursor.getColumnIndex(DbSettings.DbEntry.COL_FAV_URL)
              val idxDate:Int = cursor.getColumnIndex(DbSettings.DbEntry.COL_FAV_DATE)
              mfav.add(Favorites(cursor.getLong(idxID),cursor.getString(idxURL),cursor.getLong(idxDate)))
          }
          cursor.close()
          db.close()
      }
  
  }
  </code></pre>
  
  <p>tried with following line of code</p>
  
  <pre><code>var mFavViewModel = ViewModelProviders.of(activity).get(FavouritesViewModel::class.java)
  implementation 'android.arch.lifecycle:extensions:1.1.1'
  </code></pre>
  
  <p>this is giving error:</p>
  
  <pre><code>  Caused by: java.lang.RuntimeException: Cannot create an instance of class com.nearex.mykotlinsample.viewmodel.FavoritesDataViewModel
              at android.arch.lifecycle.ViewModelProvider$NewInstanceFactory.create(ViewModelProvider.java:153)
              at android.arch.lifecycle.ViewModelProvider$AndroidViewModelFactory.create(ViewModelProvider.java:210)
              at android.arch.lifecycle.ViewModelProvider.get(ViewModelProvider.java:134)
              at android.arch.lifecycle.ViewModelProvider.get(ViewModelProvider.java:102)
              at com.nearex.mykotlinsample.view.MainActivity.onCreate(MainActivity.kt:29)
  </code></pre>