Android数据绑定无法解析符号(gradle 3.0.1)

我想我可能会丢失一些明显的东西,绑定无法访问我的textview ID?例如。Android数据绑定无法解析符号(gradle 3.0.1)

binding.myText.setText(“text here”); >无法解析符号 '会将myText'


MainActivity.java

public class MainActivity extends AppCompatActivity { 

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

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

binding.myText.setText("test");

}

}


activity_main.xml中

<?xml version="1.0" encoding="utf-8"?> 

<layout xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:app="http://schemas.android.com/apk/res-auto">

<android.support.constraint.ConstraintLayout

android:layout_width="match_parent"

android:layout_height="match_parent">

<TextView

android:id="@+id/myText"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

app:layout_constraintBottom_toBottomOf="parent"

app:layout_constraintLeft_toLeftOf="parent"

app:layout_constraintRight_toRightOf="parent"

app:layout_constraintTop_toTopOf="parent"/>

</android.support.constraint.ConstraintLayout>

</layout>

编辑


应用程序/的build.gradle 应用插件: 'com.android.application'

android { 

compileSdkVersion 26

defaultConfig {

applicationId "com.example.francoismarais.myapplication"

minSdkVersion 15

targetSdkVersion 26

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

}

}

dependencies {

implementation fileTree(dir: 'libs', include: ['*.jar'])

implementation 'com.android.support:appcompat-v7:26.1.0'

implementation 'com.android.support.constraint:constraint-layout:1.0.2'

testImplementation 'junit:junit:4.12'

androidTestImplementation 'com.android.support.test:runner:1.0.1'

androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'

}

的build.gradle(根)

// Top-level build file where you can add configuration options common to all sub-projects/modules. 

buildscript {

repositories {

google()

jcenter()

}

dependencies {

classpath 'com.android.tools.build:gradle:3.0.1'

// NOTE: Do not place your application dependencies here; they belong

// in the individual module build.gradle files

}

}

allprojects {

repositories {

google()

jcenter()

}

}

task clean(type: Delete) {

delete rootProject.buildDir

}

回答:

dependencies { 

classpath 'com.android.tools.build:gradle:3.0.0'

// NOTE: Do not place your application dependencies here; they belong

// in the individual module build.gradle files

}

gradle:3.0.1变化到gradle:3.0.0

以上是 Android数据绑定无法解析符号(gradle 3.0.1) 的全部内容, 来源链接: utcz.com/qa/261985.html

回到顶部