android – Gradle:没有指定资源类型(‘text’的值为’@ {user.name}’).数据绑定不起作用

android – Gradle:没有指定资源类型(‘text’的值为’@ {user.name}’).数据绑定不起作用,第1张

概述我试图在我的项目中添加适当的数据绑定功能,但由于某种原因,它仍然失败. build.gradle文件如下所示: apply plugin: 'com.android.application'buildscript { repositories { mavenCentral() } dependencies { classpath 'me 我试图在我的项目中添加适当的数据绑定功能,但由于某种原因,它仍然失败.

build.gradle文件如下所示:

apply plugin: 'com.androID.application'buildscript {    repositorIEs {        mavenCentral()    }    dependencIEs {        classpath 'me.tatarka:gradle-retrolambda:3.2.5'    }}repositorIEs {    mavenCentral()}apply plugin: 'com.androID.application'apply plugin: 'me.tatarka.retrolambda'androID {    compileSdkVersion 23    buildToolsversion "24.0.0 rc4"    defaultConfig {        applicationID "boilerplate"        minSdkVersion 16        targetSdkVersion 23        versionCode 1        versionname "1.0"    }    buildTypes {        release {            MinifyEnabled false            proguardfiles getDefaultProguardfile('proguard-androID.txt'),'proguard-rules.pro'        }    }    compileOptions {        sourceCompatibility JavaVersion.VERSION_1_8        targetCompatibility JavaVersion.VERSION_1_8    }    dataBinding {        enabled = true    }}dependencIEs {    compile filetree(dir: 'libs',include: ['*.jar'])    testCompile 'junit:junit:4.12'    compile 'com.androID.support:appcompat-v7:23.4.0'    compile 'com.androID.support:design:23.4.0'    compile 'io.reactivex:rxandroID:1.2.0'    compile 'io.reactivex:rxjava:1.1.5'    compile 'com.jakewharton.rxbinding:rxbinding:0.4.0'}

布局文件如下所示:

<?xml version="1.0" enCoding="utf-8"?><linearLayout xmlns:androID="http://schemas.androID.com/apk/res/androID"              androID:orIEntation="vertical"              androID:layout_wIDth="match_parent"              androID:layout_height="match_parent">    <data>        <variable name="user" type="boilerplate.usermodel"/>    </data>    <button androID:layout_wIDth="wrap_content"            androID:layout_height="wrap_content"            androID:text="Test"            androID:ID="@+ID/btn2"            androID:onClick="OnBtnClick7"            androID:layout_below="@+ID/editText3"            androID:layout_alignRight="@+ID/editText3"            androID:layout_alignEnd="@+ID/editText3"/>    <EditText        androID:layout_wIDth="wrap_content"        androID:layout_height="wrap_content"        androID:inputType="textPersonname"        androID:text="@{user.name}"        androID:ems="10"        androID:ID="@+ID/editText"        androID:layout_alignParentleft="true"        androID:layout_alignParentStart="true"/>    <EditText        androID:layout_wIDth="wrap_content"        androID:layout_height="wrap_content"        androID:inputType="textEmailAddress"        androID:ems="10"        androID:ID="@+ID/editText2"        androID:layout_below="@+ID/editText"        androID:layout_alignParentleft="true"        androID:layout_alignParentStart="true"        androID:text="@{user.email}"/>    <EditText        androID:layout_wIDth="wrap_content"        androID:layout_height="wrap_content"        androID:inputType="textPassword"        androID:ems="10"        androID:ID="@+ID/editText3"        androID:layout_below="@+ID/editText2"        androID:layout_alignParentleft="true"        androID:layout_alignParentStart="true"        androID:text="@{user.password}"/></linearLayout>

但是在尝试构建代码时我遇到了这样的错误:

错误:(23,34)Gradle:未指定资源类型(在’text’处,值为’@ {user.name}’).
错误:(38,35)Gradle:未指定资源类型(在’text’处,值为’@ {user.email}’).
错误:(49,38)Gradle:未指定资源类型(在’text’处,值为’@ {user.password}’).

我该怎么做才能解决这个问题?

解决方法 这不是布局文件的正确结构.对于数据绑定布局文件:

>根元素是< layout> (不是< linearLayout>)
>< layout>有一个孩子< data>元素,类似于你的
>您的观点将遵循< data> element作为< layout>的子元素

例如,在this sample project,我有:

<?xml version="1.0" enCoding="utf-8"?><layout xmlns:androID="http://schemas.androID.com/apk/res/androID">  <data>    <variable      name="item"      type="com.commonsware.androID.databind.basic.Item"/>  </data>  <linearLayout    androID:layout_wIDth="match_parent"    androID:layout_height="wrap_content"    androID:orIEntation="horizontal">    <ImageVIEw      androID:ID="@+ID/icon"      androID:layout_wIDth="@dimen/icon"      androID:layout_height="@dimen/icon"      androID:layout_gravity="center_vertical"      androID:contentDescription="@string/icon"      androID:padding="8dip"/>    <TextVIEw      androID:ID="@+ID/Title"      androID:layout_wIDth="wrap_content"      androID:layout_height="wrap_content"      androID:layout_gravity="left|center_vertical"      androID:text="@{item.Title}"      androID:textSize="20sp"/>  </linearLayout></layout>
总结

以上是内存溢出为你收集整理的android – Gradle:没有指定资源类型(‘text’的值为’@ {user.name}’).数据绑定不起作用全部内容,希望文章能够帮你解决android – Gradle:没有指定资源类型(‘text’的值为’@ {user.name}’).数据绑定不起作用所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1122746.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-29
下一篇 2022-05-29

发表评论

登录后才能评论

评论列表(0条)

保存