Problem and Solutions
I cant solve this error "lateinit property dataBinding has not been initialized" in android ?
By M.K. Verma · 4 May 2022

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:
-
call super method with 2 params in your
HomeActivityclass HomeActivity ... { ... override fun onCreate(savedInstanceState: Bundle?, persistentState: PersistableBundle?) { super.onCreate(savedInstanceState, persistentState) dataBinding.vm = viewModel }
OR
-
use
onCreatewith one param in yourBaseActivityopen abstract class BaseActivity<T : ViewDataBinding , VM : ViewModel> : AppCompatActivity() { lateinit var dataBinding : T lateinit var viewModel : VM override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) ...