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

后端 未结 16 1502
伪装坚强ぢ
伪装坚强ぢ 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:45

    Do this

    ActivityMainBinding binding = DataBindingUtil.setContentView(this, R.layout.activity_main);
    

    Instead of

    MainActivity binding = DataBindingUtil.setContentView(this, R.layout.activity_main);
    
    0 讨论(0)
  • 2020-12-11 00:45

    I was getting this error because i missed the tag in view xml, which is not the case here.

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

    If your gradle version is ok (1.5+) then you should try this:

    1. Go to your "some_layout.xml"
    2. Click right -> Refactor -> Rename (or SHIFT + F6)
    3. Rename your layout to "some_layout2.xml" for example
    4. Rename this file back to the original "some_layout.xml"

    This might fix the problem. Let us know.

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

    There is a simple solution.

    1. click "File" on toolbar of android studio
    2. click "Invalidate Caches and Restart", then it works.

    Hope this answer will help you.

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

    The refresh is of no use if it continues to give errors. When there are these errors it is likely that in your xml file there is a problem that the compiler did not show you when creating the layout. In fact, it may happen that this error is visible only in its "debug" folder. If an error of this type should occur, just follow the error in the debug folder and correct it from the original file. In my case the error was two duplicates of

     

    xmlns: app = "http://schemas.android.com/apk/res-auto"

    that I couldn't see

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

    I just thought based on Felipe Gualberto's Answer and I got solution difference way.

    If you have written multiple views with the same id in different XML then make it unique.

    Thank you.

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