【发布时间】:2016-01-27 05:19:38
【问题描述】:
我在 Android Studio 中遇到以下错误:
Error:(12, 42) error: package cloudwell.collectorapp.databinding does not exist
D:\Ismail\CollectorApp\app\src\main\java\cloudwell\collectorapp\services\RetailerViewObjectAdapter.java
D:\Ismail\CollectorApp\app\src\main\java\cloudwell\collectorapp\services\RetailerViewObjectHolder.java
Error:(7, 42) error: package cloudwell.collectorapp.databinding does not exist
Error:(14, 13) error: cannot find symbol class RetailerListBindBinding
Error:(15, 38) error: cannot find symbol class RetailerListBindBinding
**Error:Execution failed for task ':app:compileDebugJavaWithJavac'.
> java.lang.RuntimeException: Found data binding errors.
****/ data binding error ****msg:Cannot resolve type for retailer~ file:D:\Ismail\CollectorApp\app\src\main\res\layout\retailer_list_bind.xml loc:12:28 - 12:35 ****\ data binding error ******
retailer_list_bind.xml
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<data>
<variable name="retailer" type="cloudwell.collectorapp.services.RetailerviewObject"/>
</data>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@{retailer.rid}"/>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@{retailer.address}"/>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@{retailer.name}"/>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@{retailer.outlet}"/>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@{retailer.phone}"/>
</LinearLayout>
</layout>
RetailerViewObject.java
package cloudwell.collectorapp.services;
import android.databinding.BaseObservable;
import android.databinding.Bindable;
public class RetailerViewObject {
private final String rid;
private final String outlet;
private final String name;
private final String address;
private final String phone;
public RetailerViewObject(String rid, String outlet, String name, String address, String phone) {
this.rid = rid;
this.outlet = outlet;
this.name = name;
this.address = address;
this.phone = phone;
}
public String getRid() {
return this.rid;
}
public String getOutlet() {
return this.outlet;
}
public String getName() {
return this.name;
}
public String getAddress() {
return this.address;
}
public String getPhone() {
return this.phone;
}
}
build.gradle
apply plugin: 'com.android.application'
apply plugin: 'com.android.databinding'
android {
compileSdkVersion 'Google Inc.:Google APIs:23'
buildToolsVersion '23.0.2'
defaultConfig {
applicationId "cloudwell.collectorapp"
minSdkVersion 10
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors {
}
dataBinding {
enabled = true
}
useLibrary 'org.apache.http.legacy'
}
dependencies {
//compile fileTree(include: ['*.jar'], dir: 'libs')
//testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:recyclerview-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
compile 'com.squareup.okhttp3:okhttp:3.0.0-RC1'
compile files('libs/volley.jar')
compile files('libs/gcm.jar')
}
【问题讨论】:
-
请同时添加 RetailerviewObject 类代码
-
这里我添加了 RetailerviewObject 类。
-
显示你的 build.gradle 文件
-
添加了 bulid.gradle 文件
-
您找到问题的原因了吗?
标签: java android data-binding