Data Binding Android - Type parameter T has incompatible upper bounds : ViewDataBinding and MainActivity

后端 未结 16 1481
伪装坚强ぢ
伪装坚强ぢ 2020-12-11 00:27

I am using Android Studio 2.0 Preview 4. I\'m using Android SDK tools 25 rc1. This error persists no matter how many times I clean / rebuild project. File->Invalidate Caches

相关标签:
16条回答
  • 2020-12-11 00:40

    I'm also getting the same problem after Migrating my existing project to AndroidX and i solve it by doing below things

    Build -> Clean Project
    Build -> Rebuild Project
    

    After that

    File -> Invalidate Caches/Restart...

    0 讨论(0)
  • 2020-12-11 00:40

    After migrating to AndoridX, You need to remove old v4 or v7 widgets from the XMl .For ex - you need to replace if you are using some AppCompat widget like

    <android.support.v7.widget.AppCompatTextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textSize="11sp"
                    android:layout_alignParentRight="true"
                    android:layout_alignParentBottom="true"
                    android:tag="showMore"/>
    

    Replace it with andoridx widget

      <androidx.appcompat.widget.AppCompatTextView
                    android:id="@+id/txt_summary_desc_more"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textSize="11sp"
                    android:layout_alignParentRight="true"
                    android:layout_alignParentBottom="true"
                    android:text="Read More"/>
    

    Worked well for me.

    0 讨论(0)
  • 2020-12-11 00:41

    One of the quickest hack i use is rename the xml file back and to.

    e.g.

    rename abc_layout.xml to abc_layout2.xml. once the binding import shows error rename it back to abc_layout.xml.

    the short cut to rename is shift + F6. its way quicker that entire project rebuild. this will only remove error from one file though.

    0 讨论(0)
  • 2020-12-11 00:41

    Delete module level build folder and re-open your project.

    0 讨论(0)
  • 2020-12-11 00:42

    By default, a Binding class will be generated based on the name of the layout file, converting it to Pascal case and suffixing "Binding" to it. The above layout file was main_activity.xml so the generate class was MainActivityBinding. The problem is you are trying to create binding class manually.

    This class holds all the bindings from the layout properties (e.g. the user variable) to the layout's Views and knows how to assign values for the binding expressions. The easiest means for creating the bindings is to do it while inflating. No need to restart the Android Studio.

    0 讨论(0)
  • 2020-12-11 00:45

    Just try to Invalidate caches/Restart from File. This worked for me.

    0 讨论(0)
提交回复
热议问题