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

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

    in top level Build.Gradle file use gradle 1.5.0 or above

     dependencies {
        classpath 'com.android.tools.build:gradle:1.5.0'
    }
    

    if it is lower than 1.5.0 then use this one also in top level gradle file

            classpath "com.android.databinding:dataBinder:1.0-rc4"
    
    0 讨论(0)
  • 2020-12-11 00:57

    This solution worked for me "File -> Invalidate Caches / Restart" https://stackoverflow.com/a/32191257/2205809

    0 讨论(0)
  • 2020-12-11 01:03

    You should use:

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

    In onCreate

    MainActivity isn't the generated Binding class.

    0 讨论(0)
  • 2020-12-11 01:03

    Check the name of the binding class, here ActivityMainInitBinding is generated based on the xml file activity_mail_init.xml. If you use wrong class the error pops up.

      val binding : ActivityMainInitBinding=
            DataBindingUtil.setContentView(this, R.layout.activity_main_init)
    
    0 讨论(0)
提交回复
热议问题