20

I used DataBinding in one of my classes CardRecicleViewAdapterTech.class , but I imported a library which does not support DataBinding and I switched to butter knifefor that class. The problem is that when I run the project, Android Studio always generates a class binding related with CardRecicleViewAdapterTech.class and this causes a crash. The generated class is:

CardViewTechBinding.java

I have deleted that java file in Android Studio databinding folder, but its generated again and again even when I do not use databinding anymore in my xml or my class.

This is my layout where I do not using dataBinding

card_view_tech.xml

so that generate CardViewTechBinding.java even when I am not using dataBinding

<?xml version="1.0" encoding="utf-8"?>

<android.support.v7.widget.CardView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    xmlns:ProgressWheel="http://schemas.android.com/apk/res-auto"
        android:id="@+id/card_tech"
        android:layout_width="match_parent"
        android:layout_height="250dp"
        android:layout_gravity="center"
        android:layout_marginTop="@dimen/standard_margin"
        android:layout_marginLeft="@dimen/standard_margin"
        android:layout_marginRight="@dimen/standard_margin"
        card_view:cardCornerRadius="4dp"
        card_view:cardBackgroundColor="@color/primary_light">

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

            <TextView
                android:text="TextView"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:id="@+id/text_view_technologie_name" />

            <com.pro.soft.apppresentation.ProgressWheel
                android:id="@+id/pw_spinner"
                android:layout_width="200dp"
                android:layout_height="200dp"
                android:layout_centerInParent="true"
                ProgressWheel:pwText="Authenticating..."
                ProgressWheel:pwTextColor="#222"
                ProgressWheel:pwTextSize="14sp"
                ProgressWheel:pwRimColor="#330097D6"
                ProgressWheel:pwBarLength="60dp"
                ProgressWheel:pwBarColor="#0097D6"
                ProgressWheel:pwBarWidth="5dp"
                ProgressWheel:pwRimWidth="2dp" />
        </LinearLayout>

    </android.support.v7.widget.CardView>

I tried to restart my Pc and Invalidate cache and restart Android Studio but without success. Please help.

4
  • have you tried to clean a project? Dec 23, 2016 at 15:22
  • 1
    yes I did, nothing changes
    – JoCuTo
    Dec 23, 2016 at 16:03
  • have you tried to disable it in build.gradle file? Dec 23, 2016 at 16:09
  • I can not, becouse I use it in a few clases
    – JoCuTo
    Dec 23, 2016 at 17:23

4 Answers 4

25

In this order:

1.- Remove your file generated (build folder)
2.- Clean your project
3.- Invalidate cache and restart Android Studio
4.- Restart computer
4
  • 7
    Worked without restarting computer. Jan 11, 2018 at 17:07
  • 1
    Have to do every time I make a change in the layout file. Any alternate to avoid it? Oct 12, 2018 at 5:57
  • I'm did just the first step and it worked fine. Thanks! Mar 7, 2019 at 14:04
  • Project Span - > App -> build -> Generated. May 7, 2020 at 23:18
6

I had the same issue, and it was caused by having <layout> root tags in the XML. I did not realise that these tags were databinding related and the compiler also does not help you in this regard.

1
  • Thanks, this is the answer that helped after I had tried everything. Jul 21, 2021 at 14:09
0

In app build.gradle disable it first by using:

dataBinding { enabled = false; }

and sync the project and then enable and sync the project

2
  • I think this is not answer. May 25, 2019 at 6:48
  • I had a huge problem with gradle reusing some old generated binding files. Tried deleting gradle cache folder, restarting Android Studio etc., but this was the only solution (disable data binding - rebuild - enable data binding) which worked for me. Feb 11, 2020 at 13:15
0

Solved my problem by adding this to the build.gradle

buildFeatures {
  viewBinding false
}

and sync the project

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.