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.
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)
}
by the way Clean build , invalid and restart is not the only solution in Android studio #JustKidding :)
Regarding the error that you are facing, you actually need to specify the View:
val listViewEmployees = findViewById(R.id.listViewEmployees)
as ListView to
val listViewEmployees = findViewById<ListView>(R.id.listViewEmployees)