Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

654
Views
kotlin - resolve error in DataBindingUtil.setContentView()

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.

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

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.

over 4 years ago · Santiago Trujillo Report

0

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) 
} 
over 4 years ago · Santiago Trujillo Report

0

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)

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!