'DataBindingUtil.setContentView - Type parameter T has incompatible upper bounds

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

ActivityChecklistsBinding binding = DataBindingUtil.setContentView(this, R.layout.activity_checklists);

Before update the ADK it works fine. Is there any ideas what wrong?



Solution 1:[1]

The binding activity is automatically generated and takes the name from the layout file, not the activity class.

So if you have an activity named BeautifulActivity and the corresponding layout named sweet_layout.xml, then the generated name will be SweetLayoutBinding and not BeautifulActivityBinding.

Don't make my same mistake by confusing between MainActivity and activity_main.xml ?

Source Android Developers

Solution 2:[2]

Try This Work for sure...

  Step 1: Add this code in the build.gradle(Mobile:app)
           dataBinding {
                enabled = true
            }

        Example:
         buildTypes {
                release {
                    minifyEnabled false
                    proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
                }
            }

            **dataBinding {
                enabled = true
            }**
        }

        dependencies {
        implementation fileTree(dir: 'libs', include: ['*.jar'])
            implementation 'com.android.support:appcompat-v7:28.0.0'
            implementation 'com.android.support.constraint:constraint-layout:1.1.3'
            testImplementation 'junit:junit:4.12'
        .....
        }

        Step 2:
        Binding Can be done with Name of the .xml file as below example..
        Simply name of the xml file and prefix with binding...

        Example 1:
        if of your .xml file is activity_main.xml then Binding file should be MainActivityBinding
        Example 2:
        if of your .xml file is android_sunil.xml then Binding file should be AndroidSunilBinding

    Step 3: Sample Code:

    public class BaseObservableActivity extends AppCompatActivity {

            private ActivityBaseobservableBinding activityMainBinding;
        @Override
        protected void onCreate(@Nullable Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            activityMainBinding = DataBindingUtil.setContentView(this, R.layout.activity_baseobservable);

        }
    }

In the above code my .xml file name is activity_baseobservable so my binding class should be ActivityBaseobservableBinding activityMainBinding


--Happy Android Coding@Ambilpura

Solution 3:[3]

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

Solution 4:[4]

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

android {

dataBinding {
    enabled true
}

}

Solution 5:[5]

Go to layout "main_activity.xml"
Click right -> Refactor -> Rename
Rename the layout to "main_activity_new.xml" or anything you want
Again rename it to normal "main_activity.xml"

It fixed for me!

Solution 6:[6]

add this in build.gradle

   android{
 ....
    dataBinding 
      { 
     enabled = true
       }
...
    }

Solution 7:[7]

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

Solution 8:[8]

Check whether the parent tag is <layout> in the top of the resource file.

Solution 9:[9]

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

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

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Guido Lodetti
Solution 2 Ambilpura Sunil Kumar
Solution 3 SG.so
Solution 4 Mohammad Taqi
Solution 5 Shahbaz Ahmed
Solution 6 zmag
Solution 7 eli
Solution 8 Navin SK
Solution 9 kirti Hudda