在android中使用数据绑定时出错 [英] Error using databinding in android
问题描述
我正在尝试按照此处.我已将其包含在我的 build.gradle 文件(模块应用程序)中:
I am trying to test data binding as given in the guide here. I have included this in my build.gradle file (of module app) :
compileSdkVersion 'android-MNC'
buildToolsVersion '23.0.0 rc2'
在项目 build.gradle 文件中,我已将其包含在我的依赖项中:
In the project build.gradle file, I have included this in my dependencies :
classpath "com.android.tools.build:gradle:1.3.0-beta2"
classpath "com.android.databinding:dataBinder:1.0-rc0"
布局文件与指南中给出的完全相同.
The layout file is exactly the same as the one given in the guide.
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android">
<data>
<variable name="user" type="com.example.User"/>
</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="@{user.firstName}"/>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@{user.lastName}"/>
</LinearLayout>
</layout>
最初它给出了一个错误元素布局没有必需的属性 layout_width 和 layout_height
.
Initially it gave an error Element layout does not have the required attribute layout_width and layout_height
.
我试图通过将 match_parent 分配给两者来修复它.然后我得到了错误Error parsing XML: duplicate attribute
在我将 layout_height
和 layout_width
分配给线性布局的行上.
I tried to fix it by assigning match_parent to both. Then I got the error
Error parsing XML: duplicate attribute
on the lines where i assigned layout_height
and layout_width
to the linear layout.
我再次尝试通过删除这些属性来解决这个问题.现在每次我尝试编译时,我都会看到这个 - error: package my.package.name.databinding
does not exist.
Again I tried to fix this by removing these attributes. Now every time I try to compile, I see this- error: package my.package.name.databinding
does not exist.
代码完成在我尝试使用此布局的 Fragment 中运行良好.
The code completion is working perfectly in my Fragment where I am trying to use this layout.
那我错过了什么?
推荐答案
从我的 build.gradle 中删除 apply plugin: 'com.neenbedankt.android-apt'
解决了我的问题.
removing apply plugin: 'com.neenbedankt.android-apt'
from my build.gradle solved my problem.
这篇关于在android中使用数据绑定时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!