title: NoSuchMethodException: <init> [class android.app.Application]
body: <p>I am trying to switch my app from <code>Loader</code>s to <code>Room</code> and <code>ViewModel</code>s. I have written my own <code>App</code> class:  </p>
  
  <pre><code>class App : Application() {
  
      lateinit var database: AppDatabase
          private set
  
      override fun onCreate() {
          super.onCreate()
          instance = this
          database = Room.databaseBuilder(this, AppDatabase::class.java, AppDatabase.NAME)
                  .build()
      }
  
      companion object {
          lateinit var instance : App
      }
  }
  </code></pre>
  
  <p>And my view model:  </p>
  
  <pre><code>open class BaseViewModel&lt;TEntity, TDao: BaseDao&lt;TEntity&gt;, TRepo : Repository&lt;TEntity, TDao&gt;&gt;(
          app: App, protected val repository: TRepo) : AndroidViewModel(app) {
  
      fun insert(entity: TEntity) {
          repository.insert(entity)
      }
  
      fun update(entity: TEntity) {
          repository.update(entity)
      }
  
      fun delete(entity: TEntity) {
          repository.delete(entity)
      }
  }
  
  class TimetableViewModel(app: App) : BaseViewModel&lt;Timetable, TimetableDao, TimetableRepository&gt;(
          app, TimetableRepository(app.database)) {
  
      internal val all: LiveData&lt;List&lt;Timetable&gt;&gt; = repository.getAll()
  
  }
  </code></pre>
  
  <p>In <code>MainActivity.onCreate()</code> I initialize my <code>TimetableViewModel</code> by next line:  </p>
  
  <pre><code>timetableVM = ViewModelProviders.of(this).get(TimetableViewModel::class.java)
  </code></pre>
  
  <p>But on launch the app crashes with log:  </p>
  
  <pre><code>Caused by: java.lang.RuntimeException: Cannot create an instance of class com.contedevel.timetable.model.TimetableViewModel
          at android.arch.lifecycle.ViewModelProvider$AndroidViewModelFactory.create(ViewModelProvider.java:201)
          at android.arch.lifecycle.ViewModelProvider.get(ViewModelProvider.java:134)
          at android.arch.lifecycle.ViewModelProvider.get(ViewModelProvider.java:102)
          at com.contedevel.timetable.activity.MainActivity.onCreate(MainActivity.kt:187)
          at android.app.Activity.performCreate(Activity.java:6757)
          at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)
          at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2702)
          at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2810) 
          at android.app.ActivityThread.-wrap12(ActivityThread.java) 
          at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1528) 
          at android.os.Handler.dispatchMessage(Handler.java:102) 
          at android.os.Looper.loop(Looper.java:154) 
          at android.app.ActivityThread.main(ActivityThread.java:6312) 
          at java.lang.reflect.Method.invoke(Native Method) 
          at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:872) 
          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:762) 
       Caused by: java.lang.NoSuchMethodException: &lt;init&gt; [class android.app.Application]
          at java.lang.Class.getConstructor0(Class.java:2204)
          at java.lang.Class.getConstructor(Class.java:1683)
          at android.arch.lifecycle.ViewModelProvider$AndroidViewModelFactory.create(ViewModelProvider.java:199)
          at android.arch.lifecycle.ViewModelProvider.get(ViewModelProvider.java:134) 
          at android.arch.lifecycle.ViewModelProvider.get(ViewModelProvider.java:102) 
          at com.contedevel.timetable.activity.MainActivity.onCreate(MainActivity.kt:187) 
          at android.app.Activity.performCreate(Activity.java:6757) 
          at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119) 
          at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2702) 
          at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2810) 
          at android.app.ActivityThread.-wrap12(ActivityThread.java) 
          at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1528) 
          at android.os.Handler.dispatchMessage(Handler.java:102) 
          at android.os.Looper.loop(Looper.java:154) 
          at android.app.ActivityThread.main(ActivityThread.java:6312) 
          at java.lang.reflect.Method.invoke(Native Method) 
          at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:872) 
          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:762)
  </code></pre>