Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 615 Vote(s) - 3.51 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Cannot find the setter for attribute in Data binding

#1
I am using LiveData, DataBinding, and Kotlin in my application.

I defined a Binding Adapter for a RecyclerView like this:

class MainListBindings {

private val TAG = "TasksListBindings"

companion object {

@JvmStatic
@SuppressWarnings("unchecked")
@BindingAdapter("main_items")
fun setItems(recyclerView: RecyclerView, items: MutableLiveData<List<Homeitem>>? = null) {

val adapter: RecyclerMainAdapter = recyclerView.adapter as RecyclerMainAdapter
//prevent use of null list
items?.let {

adapter.swapData(items)
}
}

}
}

and my reyclerView in XML assigned to this bindingAdapter like this:

<android.support.v7.widget.RecyclerView
android:id="@+id/main_recycler"
app:main_items="@{viewmodel.items}"
android:layout_width="match_parent"
android:layout_height="match_parent"/>

And in my ViewModel, I used

val items = MutableLiveData<List<Homeitem>>()

to create the list.

But I am getting this error at building Application:

Found data binding errors.
****/ data binding error ****msg:Cannot find the setter for attribute 'app:main_items' with parameter type android.arch.lifecycle.MutableLiveData<java.util.List<project.data.pojo.Homeitem>> on android.support.v7.widget.RecyclerView. file:/home/user/Yara/bazinama_mag/bazinama/app/src/main/res/layout/fragment_main.xml loc:22:24 - 22:38 ****\ data binding error ****


Reply

#2
**Binding Adapter**

@JvmStatic
@BindingAdapter("main_items")
fun setItems(recyclerView: RecyclerView, items: MutableLiveData<List<String>>) {

}

**Model**


class User : ViewModel(){
lateinit var list: MutableLiveData<List<String>>
}

**Bind Data**

val items = ViewModelProviders.of(this@FragmentName)
.get(RecyclerViewHelper.User::class.java)
mBinding!!.user = items

**Layout**

<layout>
<data>
<variable
name="user"
type="com.XXX.view.recylerview.RecyclerViewHelper.User" />
</data>

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<android.support.v7.widget.RecyclerView
android:id="@+id/helper_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layoutManager="android.support.v7.widget.LinearLayoutManager"
app:main_items="@{user.list}" />

</RelativeLayout>

</layout>

Reply

#3
There might be different reasons for this error but in my case, the problem raised up because I didn't add `apply plugin: 'kotlin-kapt'` And `apply plugin: 'kotlin-android-extensions'` in my `Gradle`.

After adding these plugins you have to replaced your `annotationProcessors` with `kapt`.

After that, every thing might be going well.
Reply

#4
Check if you have any space after the `@BindingAdapter` value like this:
```
@BindingAdapter("sleepDurationFormatted ")
^
|
here
```
Took me 2hours to find out.
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through