UninitializedPropertyAccessException: lateinit property pref has not been initialized

后端 未结 1 768
遥遥无期
遥遥无期 2020-12-31 00:01

I know a similar question has been answered Here. But that was due to butter knife library problem but my case is different. In my case when I use dagger injected properties

相关标签:
1条回答
  • 2020-12-31 00:35

    You can't use an object before you initialize it.

    override fun onCreate(savedInstanceState: Bundle?) {
      super.onCreate(savedInstanceState) // prefs called in parents onCreate!
      setContentView(R.layout.activity_login)
      AndroidInjection.inject(this) // injection happens here
    

    Get your calls in order. Easiest way to fix would be to move AndroidInjection.inject(this) before the call to super.onCreate(...).

    0 讨论(0)
提交回复
热议问题