alexa

I cant solve this error "lateinit property dataBinding has not been initialized" in android ?

I cant solve this error "lateinit property dataBinding has not been initialized" in android ?

When you are calling super.onCreate(savedInstanceState) in your HomeActivity, the onCreate from android's Activity is called, but not the onCreate from BaseActivity - because it expected second param persistentState.

So you can do this options to fix the issue:

  1. call super method with 2 params in your HomeActivity

     class HomeActivity ... {
    ...
        override fun onCreate(savedInstanceState: Bundle?, persistentState: PersistableBundle?) {
            super.onCreate(savedInstanceState, persistentState) 
            dataBinding.vm = viewModel
        } 

OR

  1. use onCreate with one param in your BaseActivity

     open abstract class BaseActivity<T : ViewDataBinding , VM : ViewModel> : AppCompatActivity() {
    
        lateinit var dataBinding : T
        lateinit var viewModel : VM
    
        override fun onCreate(savedInstanceState: Bundle?) {
            super.onCreate(savedInstanceState)
           ...

289 0
7

Write a Comments


* Be the first to Make Comment

GoodFirms Badge
GoodFirms Badge

Fix Your Meeting With Our SEO Consultants in India To Grow Your Business Online

Facebook
Twitter
LinkedIn
Instagram
Whatsapp
Call Now
Quick Inquiry