*BindingImpl class : cannot inherit from final *Binding

Viewed 5251

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>
4 Answers

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

This solved a similar issue in my project.

I had this error because I had multiple xml files for the same layout (e.g fragment_xxx, fragment_xxx_land, fragment_xxx_sw600dp etc.) changed one layout and forgot to update the other ones. So if you have multiple layouts, make sure that all have the same tags / are similar.

Also clean project and rebuild worked for me!

its because your viewmodel package is not same as the one it is in. like the viewmodel class is laying somewhere else while the package inside the viewmodel class is pointing to somewhere else so please make it same as the location of viewmodel inside your viewmodel class

inshort recheck if your ImageViewModel is lying in same place as this one com.example.memoriserlesnombres.image.ImageViewModel if the location is different from the package then change the package inside the ImageViewModel class to the location this class is in...

also change the ImageViewModel location in xml file too... and you are good to go...

this error sometime i mean very rarly arise when you copy a class from one package to another package inside the class...

enter image description here

Related