wee*_*oos 7 java data-binding android
我的伙伴在我们的'项目中使用android databinding.in我的电脑有错误,但在他的mac不错误.我无法解决这个程序.请帮助!! 这是我的构建gradle:
dataBinding {
enabled = true
}
Run Code Online (Sandbox Code Playgroud)
第一个构建androidstudio说
com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException: Invalid byte 2 of 2-byte UTF-8 sequence.
Run Code Online (Sandbox Code Playgroud)
然后我重新保存XML文件使用UTF-8.但是出现了一个新问题.就像这样:
:app:dataBindingProcessLayoutsDebug
line 1:0 mismatched input '?' expecting {COMMENT, SEA_WS, '<', PI}
Error:Execution failed for task ':app:dataBindingProcessLayoutsDebug'.
Run Code Online (Sandbox Code Playgroud)
java.lang.NullPointerException(无错误消息)
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:bind="http://schemas.android.com/apk/res-auto">
<data>
<import type="android.view.View"/>
<import type="com.vomoho.vomoho.common.Utils"/>
<variable name="postDetail" type="com.vomoho.vomoho.entity.PostDetail" />
</data>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
android:orientation="vertical">
<include
android:id="@+id/top"
layout="@layout/dt_item_postdetail_top"
bind:postDetail="@{postDetail}"/>
<ImageView
android:id="@+id/img1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_marginTop="8dp"
android:scaleType="centerCrop"
android:visibility="@{Utils.getPostType(postDetail.picList) == 0 ? View.GONE : View.VISIBLE}"
bind:imageUrl="@{postDetail.picList.size() > 0 ? postDetail.picList.get(0) : ``}"
bind:width="@{Utils.getPostImgWidth(Utils.getPostType(postDetail.picList))}"
bind:height="@{Utils.getPostImgHeight(Utils.getPostType(postDetail.picList))}" />
<include
android:id="@+id/bottom"
layout="@layout/dt_item_postdetail_bottom"
bind:postDetail="@{postDetail}"/>
</LinearLayout>
</layout>
Run Code Online (Sandbox Code Playgroud)
我有同样的问题,我终于找到了解决方案.
我发现有一个布局xml文件是这样编写的:
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text='@{"?? " + String.valueOf(user.age)}'/>
Run Code Online (Sandbox Code Playgroud)
然后它不能建立在Windows平台上,但它可以建立在Mac OS X平台上,我认为它是Android数据绑定的一个bug,所以我的临时解决方案是:
不要在@{}节中写任何字符,而是使用字符串引用.(在我的情况下,它的替换为android:text='@{ @string/age_text + String.valueOf(user.age) }'/>)
希望它可以帮助你.
小智 2
我也有这个错误。就我而言,布局文件底部有一个多余的 xml 标头。
尝试删除空格(或删除标题),更改:
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
Run Code Online (Sandbox Code Playgroud)
到...
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5402 次 |
| 最近记录: |