Unresolved reference: databinding when importing databinding to MainActivity
Looks like I was missing the layout tag in the layout to support Databinding:
<layout xmlns:android="http://schemas.android.com/apk/res/android">
Android Studio Kotlin databinding: Unresolved reference on BR
What fixed the problem for me was adding the following import to my files:
import androidx.databinding.library.baseAdapters.BR
I'm not entirely certain why this works, but it got rid of all the analysis problems and the application still compiles and works fine, so I'm personally happy.
Databinding: unresolved reference for variable name
The problem is that you reference a binding class of the MainActivity
which is (ActivityMainBinding
) to the DetailActivity
.
Therefore, it can't find a setResult()
method in the ActivityMainBinding
, because there is no result
variable in activity_main.xml
layout.
Notice that each activity has a unique generated class that bounds to its own layout.
To fix this you need to replace ActivityMainBinding
with ActivityDetailBinding
class DetailActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val activityDetailBinding: ActivityDetailBinding = DataBindingUtil.setContentView(this, R.layout.activity_detail)
val model: Result = intent.getSerializableExtra("movieModel") as Result
activityDetailBinding.setResult = model
}
}
Related Topics
Android and Getting a View with Id Cast as a String
Urlconnection Getcontentlength() Is Returning a Negative Value
How to Simulate Low Memory in the Android Emulator
"Hello World" Android App with as Few Files as Possible, No Ide, and Text Editor Only
Changing Openssl Library in Android App for Httpclient
Apache Http Client or Urlconnection
How to Instantiate an Abstract Class Directly
Broadcastreceiver for Action_Media_Button Not Working
Why Does My Compare Method Throw Exception -- Comparison Method Violates Its General Contract!
What Is an Index in Elasticsearch
How to Persist Permission in Android API 19 (Kitkat)
Cannot Resolve Method Getmap()
Is Dalvik's Memory Model the Same as Java'S
How to Do an Https Post from Android
Double Tap: Zoom on Android Mapview
Why Do We Have to Call Super in Android Sometimes