Oussama Safi
Oussama Safi

Reputation: 1

Android Kotlin generated databinding classes contain errors

I am a beginner in android program development and I have been trying to get familiar with using databindings. I followed the correct steps to generate my databinding classes but whenever I try to use my generated classes in my program null is always returned. After having a look at many possible causes, I realised that the databinding class extends the wrong super class. Below is one of my generated classes

public class FragmentDuosBindingImpl extends FragmentDuosBinding  {

@Nullable
private static final androidx.databinding.ViewDataBinding.IncludedLayouts sIncludes;
@Nullable
private static final android.util.SparseIntArray sViewsWithIds;
static {
    sIncludes = null;
    sViewsWithIds = null;
}
// views
@NonNull
private final androidx.constraintlayout.widget.ConstraintLayout mboundView0;
// variables
// values
// listeners
// Inverse Binding Event Handlers

public FragmentDuosBindingImpl(@Nullable androidx.databinding.DataBindingComponent bindingComponent, @NonNull View root) {
    this(bindingComponent, root, mapBindings(bindingComponent, root, 1, sIncludes, sViewsWithIds));
}
private FragmentDuosBindingImpl(androidx.databinding.DataBindingComponent bindingComponent, View root, Object[] bindings) {
    super(bindingComponent, root, 0
        );
    this.mboundView0 = (androidx.constraintlayout.widget.ConstraintLayout) bindings[0];
    this.mboundView0.setTag(null);
    setRootTag(root);
    // listeners
    invalidateAll();
}

@Override
public void invalidateAll() {
    synchronized(this) {
            mDirtyFlags = 0x1L;
    }
    requestRebind();
}

@Override
public boolean hasPendingBindings() {
    synchronized(this) {
        if (mDirtyFlags != 0) {
            return true;
        }
    }
    return false;
}

@Override
public boolean setVariable(int variableId, @Nullable Object variable)  {
    boolean variableSet = true;
        return variableSet;
}

@Override
protected boolean onFieldChange(int localFieldId, Object object, int fieldId) {
    switch (localFieldId) {
    }
    return false;
}

@Override
protected void executeBindings() {
    long dirtyFlags = 0;
    synchronized(this) {
        dirtyFlags = mDirtyFlags;
        mDirtyFlags = 0;
    }
    // batch finished
}
// Listener Stub Implementations
// callback impls
// dirty flag
private  long mDirtyFlags = 0xffffffffffffffffL;
/* flag mapping
    flag 0 (0x1L): null
flag mapping end*/
//end}

As you can see, this generated class does not resemble a typical databinding class. The class extends the FragmentDuosFragment class instead of the ViewDataBinding class. I cannot access any of my elements which are shown below

<?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"
tools:context="safi.oussama.codwarzonesquadlink.Fragments.DuosFragment">

<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">

<ListView
    android:layout_width="405dp"
    android:layout_height="505dp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>
</layout>

Below is the code from my fragment used to inflate the layout and generate the databinding classes

override fun onCreateView(
    inflater: LayoutInflater, container: ViewGroup?,
    savedInstanceState: Bundle?
): View? {

    val binding:ViewDataBinding=DataBindingUtil.inflate(
        inflater, R.layout.fragment_duos, container, false
    )

    return binding.root}

I have searched quite a bit on this issue and have found nothing closely resembling this error. And of course, I cannot edit the code of a generated class. I would greatly appreciate a solution or some hints that could help me discover the fault

Upvotes: 0

Views: 940

Answers (1)

ezaspi
ezaspi

Reputation: 714

Sorry this is late, but I just ran into this issue and a solution. It looks like you use Included Layouts. The xml layout being included needs to be wrapped in a layout. Solution

Upvotes: 2

Related Questions