在Android中使用数据绑定错误 [英] Error using databinding in android

查看:186
本文介绍了在Android中使用数据绑定错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试测试数据绑定,如指南这里
我把这个包含在我的build.gradle文件(模块应用程序)中:

  compileSdkVersion'android-MNC' 
buildToolsVersion '23 .0.0 rc2'

在项目build.gradle文件中,我有包含在我的依赖项中:

  classpathcom.android.tools.build:gradle:1.3.0-beta2
classpathcom.android.databinding:dataBinder:1.0-rc0

布局文件正好与指南中给出的相同。

 <?xml version =1.0encoding =utf-8 ?> 
< layout xmlns:android =http://schemas.android.com/apk/res/android>
< data>
< variable name =usertype =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



我尝试通过将match_parent分配给这两个来修复它。然后我得到错误
在我分配了 layout_height 和的行上解析XML:重复属性 code> layout_width 到线性布局。



我再次尝试通过删除这些属性来解决这个问题。现在每次我尝试编译时,我看到这个 - 错误:package my.package.name.databinding 不存在。



/ p>

那么我错过了什么?

解决方案

删除应用插件:'我的build.gradle解决了'com.neenbedankt.android-apt'我的问题。


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'

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>

Initially it gave an error Element layout does not have the required attribute layout_width and layout_height.

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.

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.

The code completion is working perfectly in my Fragment where I am trying to use this layout.

So what did I miss ?

解决方案

removing apply plugin: 'com.neenbedankt.android-apt' from my build.gradle solved my problem.

这篇关于在Android中使用数据绑定错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆