DataBindingUtil.setContentView - Type parameter T has incompatible upper bounds

前端 未结 9 737
逝去的感伤
逝去的感伤 2021-02-02 06:54

\"Android Studio\" shows error message \"Type parameter T has incompatible upper bounds: ViewDataBinding and ActivityChecklistsBinding.

ActivityChecklistsBindin         


        
相关标签:
9条回答
  • 2021-02-02 07:00

    Add this is your build.gradle(Module:app) file

    android {

    dataBinding {
        enabled true
    }
    

    }

    0 讨论(0)
  • 2021-02-02 07:01

    I had the same problem. I tried a couple of things, Clean and Rebuild project.

    But, It worked after I choose File -> Invalidate Caches / Restart

    0 讨论(0)
  • 2021-02-02 07:06

    When I first meet this error, I create a layout named a.xml, and then I Create a Activity like this

    public class ABinding extends AppCompatActivity {
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            ABinding binding = DataBindingUtil.setContentView(this, R.layout.a);
        }
    
    }
    

    and this error occurs. Finally I found out Class ABinding was automatically generated in /build, so activity with name ABinding will overwrite the auto generated class

    so I rename the Activity and the error disappear

    0 讨论(0)
  • 2021-02-02 07:09

    add this in build.gradle

       android{
     ....
        dataBinding 
          { 
         enabled = true
           }
    ...
        }
    
    0 讨论(0)
  • 2021-02-02 07:12

    If all the solutions mentioned above didn't work out go to your .gradle folder > caches and delete all folders with name starting with transforms i.e. transforms-1 & transforms-2. This works for me

    0 讨论(0)
  • 2021-02-02 07:12

    You should use ActivityMainBinding in place of your Activity class name.

    ActivityMainBinding binding = DataBindingUtil.setContentView(this, R.layout.activity_checklists);
    
    0 讨论(0)
提交回复
热议问题