0

The error says: Cannot resolve setContentView for DataBinding.

I tried to fix this issue like here Android Data binding : Cannot resolve symbol but nothing happens.

I tried to invalidate and restart studio. I tried to clean and rebuild project

Nothing happens. I searched and other articles and say the same thing.

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import com.android.example.applicationtest.databinding.ActivityMainBinding;
import android.databinding.DataBindingUtil;

public class MainActivity extends AppCompatActivity {

private ActivityMainBinding mBinding;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

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


}
}



apply plugin: 'com.android.application'

android {
compileSdkVersion 27
defaultConfig {
    applicationId "com.android.example.applicationtest"
    minSdkVersion 19
    targetSdkVersion 27
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
dataBinding {
    enabled = true
}
buildToolsVersion '27.0.3'
}
Nick
  • 2,818
  • 5
  • 42
  • 60

2 Answers2

2

You don't need to write new for DataBindingUtil.

You just need to write DataBindingUtil.setContentView()

This is because setContentView() is a static method of DataBindingUtil.

Kruti Parekh
  • 1,271
  • 9
  • 21
  • I have posted a question and one of the answers told me about the `dataBinding` but I am facing an issue with it kindly check the [answer](https://stackoverflow.com/a/73494115/6854117)? – Moeez Aug 27 '22 at 09:46
1
use this code 

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

//---------------

remove  "new"
Vishal Sharma
  • 1,051
  • 2
  • 8
  • 15
  • your are use new keyword on this code ActivityMainBinding mBinding = new DataBindingUtil.setContentView(this,R.layout.activity_main); – Vishal Sharma Jul 14 '18 at 12:31
  • if you are facing any other problem let me know. Thank you – Vishal Sharma Jul 14 '18 at 12:32
  • I actually have: https://stackoverflow.com/questions/51340516/android-binding-type-associated-with-an-element-type-variable-must-not-conta – Nick Jul 14 '18 at 14:42