\"Android Studio\" shows error message \"Type parameter T has incompatible upper bounds: ViewDataBinding and ActivityChecklistsBinding.
ActivityChecklistsBindin
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!
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
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