title: App crashing because lateinit App instance not initialized
body: <p>I am trying to save an Application instance and use in the constructor of databaseHelper, but when my activity tries to instantiate the databaseHelper I get the following exceptions: </p>
  
  <pre><code>FATAL EXCEPTION: 
  main Process: com.weatherupp.weatherupp, PID: 29092
  java.lang.ExceptionInInitializerError
  at com.weatherupp.weatherupp.ui.MainActivity.onCreate(MainActivity.kt:27)
  [...]
  Caused by: kotlin.UninitializedPropertyAccessException: lateinit 
  property instance has not been initialized
  </code></pre>
  
  <p>the code leading to the exception is the following:</p>
  
  <pre><code>MainActivity {
  override fun onCreate(savedInstanceState: Bundle?) {
  super.onCreate(savedInstanceState)
  val provider = ForecastProvider()
  [...]
  }
  </code></pre>
  
  <p>ForecastProvider has the following companion object:</p>
  
  <pre><code>companion object {
      val SOURCES = listOf(ForecastServer(), ForecastDb())
  }
  </code></pre>
  
  <p>ForecastDb's constructor refers to an instance of ForecastDbHelper, whose constructor refers to App.instance, declared as follows:</p>
  
  <pre><code>class App : Application() {
  
    companion object {
      lateinit var instance: App
    }
  
    override fun onCreate() {
      super.onCreate()
      instance = this
    }
  
  }
  </code></pre>
  
  <p>If I comment all the code referring to the database, the app works using ForecastServer as the source of data, but the moment I try to refer to the database and hence to the App istance, Kotlin throws the UninitializedPropertyAccessException. </p>
  
  <p>I have been looking at the code for hours, can't figure out what I am doing wrong. Any help is blessed, thank all of you in advance. </p>