Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

*BindingImpl class : cannot inherit from final *Binding

I got this error in the generated BindingImpl class but the binding class is not final, it is abstract...

BindingImpl class :

public class FragmentImageBindingImpl extends FragmentImageBinding implements com.example.memoriserlesnombres.generated.callback.OnClickListener.Listener {
...
}

Binding class:

public abstract class FragmentImageBinding extends ViewDataBinding {
...
}

Any ideas ?

I already try to clean/rebuilt project, invalidate caches/restart and reinstall android studio without success. I saw another post saying to delete plugin files but they don't exist.

I'm new to android, but it seems very buggy to me :/

EDIT : I still have the error (in the class) but my app works fine, so I think I can ignore it, this is just an Android Studio issue.

Here is the xml :

<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools">

    <data>

        <variable
            name="view"
            type="com.example.memoriserlesnombres.image.ImageViewModel" />
    </data>

    <androidx.coordinatorlayout.widget.CoordinatorLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <androidx.constraintlayout.widget.ConstraintLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            tools:context=".image.ImageFragment">

            <TextView
                android:id="@+id/current_number"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@{Integer.toString(view.currentNumber)}"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent" />

            <com.google.android.material.textfield.TextInputLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/current_number">

                <com.google.android.material.textfield.TextInputEditText
                    android:id="@+id/associated_image"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:hint="@string/hint"
                    android:text="@={view.image}" />
            </com.google.android.material.textfield.TextInputLayout>

        </androidx.constraintlayout.widget.ConstraintLayout>

        <com.google.android.material.floatingactionbutton.FloatingActionButton
            android:id="@+id/fab"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="end|bottom"
            android:layout_margin="16dp"
            android:contentDescription="@string/save_image"
            android:onClick="@{() -> view.saveImage()}"
            app:srcCompat="@drawable/ic_done_black_24dp" />

    </androidx.coordinatorlayout.widget.CoordinatorLayout>
</layout>
like image 300
gfx Avatar asked Aug 09 '20 16:08

gfx


People also ask

What is ActivityMainBindingImpl?

xml so the corresponding generated class is ActivityMainBinding. This class holds all the bindings from the layout properties (for example, the user variable) to the layout's views and knows how to assign values for the binding expressions. In my case ActivityMainBinding is generated, but not ActivityMainBindingImpl.

What is ViewDataBinding?

android.databinding.ViewDataBinding. Base class for generated data binding classes. If possible, the generated binding should be instantiated using one of its generated static bind or inflate methods. If the specific binding is unknown, bind(View) or inflate(LayoutInflater, int, ViewGroup, boolean) should be used.

How do you create a binding class?

A binding class is generated for each layout file. By default, the name of the class is based on the name of the layout file, converting it to Pascal case and adding the Binding suffix to it. The above layout filename is activity_main. xml so the corresponding generated class is ActivityMainBinding.


Video Answer


1 Answers

In one of your layout xml files, remove the <layout> tag and add it back.

This solved a similar issue in my project.

like image 97
Yu Jinyan Avatar answered Sep 20 '22 13:09

Yu Jinyan