Android数据绑定无法解析符号(gradle 3.0.1)
我想我可能遗漏了一些明显的东西,绑定无法访问我的textview id?例如 binding.myText.setText(“此处文本”);>无法解析符号“myText”Android数据绑定无法解析符号(gradle 3.0.1),android,android-databinding,Android,Android Databinding,我想我可能遗漏了一些明显的东西,绑定无法访问我的textview id?例如 binding.myText.setText(“此处文本”);>无法解析符号“myText” MainActivity.java public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCrea
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");
}
}
活动\u 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(根)
将gradle:3.0.1
更改为gradle:3.0.0
将
gradle:3.0.1
更改为gradle:3.0.0
是否尝试清理/重建?我尝试了,让我尝试使缓存无效并重新启动。我还添加了我的gradle文件,可能是缺少了一些内容:|好吧,我做了一个使缓存无效并重新启动的操作,现在似乎已经将其踢到了工作状态:)很抱歉这个明显的问题,您是否尝试了清理/重建?我做了,让我尝试使缓存无效并重新启动。我还添加了我的gradle文件,可能缺少一些东西:|好吧,我做了一个使缓存无效并重新启动的操作,这似乎使它现在进入了工作状态:)很抱歉出现了明显的问题无效缓存和重新启动似乎起了作用:)-这不是一个解决方案。无效缓存和重新启动似乎起了作用:)-这不是一个解决方案。
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'
}
// 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
}