title: UninitializedPropertyAccessException: lateinit property pref has not been initialized
body: <p>I know a similar question has been answered <a href="https://stackoverflow.com/questions/40176083/lateinit-property-has-not-been-initialized">Here</a>. But that was due to butter knife library problem but my case is different. In my case when I use dagger injected properties in my base activity it shows me error <strong>Caused by: kotlin.UninitializedPropertyAccessException: lateinit property pref has not been initialized</strong></p>
  
  <p>But the same property when I use in my sub activity (Login activity) it works fine. </p>
  
  <p>eg. <strong>pref.setLanguage("abc") -> it works fine in login activity but throws error in base activity</strong> </p>
  
  <p>Here is my code:</p>
  
  <p><strong>BaseActivity</strong></p>
  
  <pre class="lang-kotlin prettyprint-override"><code>    abstract class BaseActivity : AppCompatActivity() {
      @Inject
      lateinit var pref: AppSharedPreferences
      @Inject
      lateinit var utils: Utils
      lateinit var mCurrentLanguage: String
      protected lateinit var progressBarUtils: ProgressBarUtils
  
      override fun onCreate(savedInstanceState: Bundle?) {
          super.onCreate(savedInstanceState)
          progressBarUtils = ProgressBarUtils(this)
          mCurrentLanguage = "EN"
          pref.setSelectedLanguage(mCurrentLanguage)   
      }
      }
  </code></pre>
  
  <p><strong>LoginActivity</strong></p>
  
  <pre class="lang-kotlin prettyprint-override"><code>    class LoginActivity : BaseActivity() {
      private val TAG = this.javaClass.name
      lateinit var loginViewModel: LoginViewModel
      @Inject
      lateinit var viewModelFactory: LoginViewModelFactory
  
  
      override fun onCreate(savedInstanceState: Bundle?) {
          super.onCreate(savedInstanceState)
          setContentView(R.layout.activity_login)
          AndroidInjection.inject(this)
          loginViewModel = ViewModelProviders.of(this, viewModelFactory).get(
                  LoginViewModel::class.java)
          loadData("abc", "xyz")
          observerOnLoginResult()
          observerOnLoginError()
      }
  
  
      private fun observerOnLoginError() {
          loginViewModel.loginError().observe(this, Observer&lt;String&gt; {
              progressBarUtils.cancelProgressDialog()
              if (it != null) {
                  Toast.makeText(this, resources.getString(R.string.error_message) + it,
                          Toast.LENGTH_SHORT).show()
              }
          })
      }
  
      private fun observerOnLoginResult() {
          loginViewModel.loginResult().observe(this,
                  Observer&lt;LoginModel&gt; {
                      progressBarUtils.cancelProgressDialog()
                      if (it != null) {
                          setData(it)
                      }
                  })
      }
  
      private fun setData(loginData: LoginModel) {
          pref.setCurrentUserName(loginData.data.userName)
      }
  
      private fun loadData(email: String, password: String) {
          progressBarUtils.showProgressDialog()
          val builder = StringBuilder()
          var auth = Base64.encodeToString(("$email:$password").toByteArray(), Base64.NO_WRAP)
          builder.append("Basic ")
          builder.append(auth)
          loginViewModel.getLoginData(builder.toString())
      }
  
      override fun onDestroy() {
          loginViewModel.disposeElements()
          super.onDestroy()
      }
  </code></pre>
  
  <p><strong>AppModule</strong>  </p>
  
  <pre class="lang-kotlin prettyprint-override"><code>    @Module class AppModule(val app: Application) {
  
      @Provides
      @Singleton
      fun provideApplication(): Application = app
  
  
      @Provides
      @Singleton
      fun provideSharedPreferences(): AppSharedPreferences = AppSharedPreferences(app)
  
  
      @Provides
      @Singleton
      fun provideUtils(): Utils = Utils(app)
      }
  </code></pre>
  
  <p><strong>Builder Module</strong>    </p>
  
  <pre class="lang-kotlin prettyprint-override"><code>    @Module abstract class BuildersModule {
  
      @PerActivity
      @ContributesAndroidInjector(modules = arrayOf(LoginModule::class))
      abstract fun contributeLoginActivity(): LoginActivity
  
      @PerActivity
      abstract fun contributeBaseActivityActivity(): BaseActivity
      }
  </code></pre>
  
  <p><strong>AppComponent</strong></p>
  
  <pre class="lang-kotlin prettyprint-override"><code>    @Singleton @Component(
          modules = arrayOf(AndroidInjectionModule::class, AppModule::class, BuildersModule::class))
  
      interface AppComponent { 
        fun inject(app: LotusApp)            
      }
  
  </code></pre>