I am facing problem in DataBindingUtil.setContentView()
. It is showing the following error.
[Type inference failed: Not enough information to infer parameter T in fun setContentView(p0: Activity, p1: Int): T! Please specify it explicitly.
MY Code :
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
// setContentView(R.layout.activity_home) var binding =
DataBindingUtil.setContentView(this, R.layout.activity_home)
}
Anyone help me resolve this error. I have done clean and Rebuild(Invalidate and Restart)
also.
Please let me know any other suggestion.
This method sets the activity content to an explicit view. SetContentView() method is 3 types. This view is placed directly into the activity's view hierarchy. Calling this function “locks in” various characteristics of the window that can not, from this point forward, be changed.
Use:
var binding : ActivityHomeBinding = DataBindingUtil.setContentView(this, R.layout.activity_home)
DataBindingUtil.setContentView
is returning the binding of the particular layout file passed in as parameter.
Create a binding object like this.
val binding: ActivityMainBinding = DataBindingUtil.setContentView(
this, R.layout.activity_main)
You have to mention the Activity Binding type. I have the Main activity so the binding type is ActivityMainBinding
. This is what you have missed.
It should be like this:
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_home)
var binding : ActivityMainBinding =
DataBindingUtil.setContentView(this, R.layout.activity_home)
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With