Android BindingAdapter error.NonExistentClass

Viewed 1462

Here it is my BindingAdapter

@InverseBindingMethods({
        @InverseBindingMethod(type = RecyclerView.class, attribute = "lastAdapter", method = "getLastAdapter"),
})
public class RecyclerViewBindingAdapter {
    @BindingAdapter(value = {"lastAdapter"}, requireAll = false)
    public static void setLastAdapter(RecyclerView view, LastAdapter adapter) {
        view.setAdapter(adapter);
    }

    @InverseBindingAdapter(attribute = "lastAdapter")
    public static LastAdapter getLastAdapter(RecyclerView view) {
        return (LastAdapter) view.getAdapter();
    }
}

I have added RecyclerView dependency on my gradle:

compile "com.android.support:recyclerview-v7:25.3.1"

Here it is how I use in my layout:

<android.support.v7.widget.RecyclerView
 app:lastAdapter = "@{viewModel.adapter}"
 ... />

I have already set the viewModel binding variable after inflating this layout. But whenever I run my codes, gradle always shows the following error

Error:(48, 34) Cannot find the setter for attribute 'app:lastAdapter' with parameter type error.NonExistentClass on android.support.v7.widget.RecyclerView. 

I can resolve this problem by removing any app:lastAdapter from my layouts then clean and rebuild, rewrite those app:lastAdapter attibutes again then rebuild project, everything works fine.

That is not a convenient solving.

2 Answers

Run this command inside android studio terminal and build project again

./gradlew clean assemble

Related