my partner in ours' project use android databinding.in my pc had error,but in his mac not error.i cant resolve this program.please help:! it's my build.gradle:
dataBinding {
enabled = true
}
the first build androidstudio say
com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException: Invalid byte 2 of 2-byte UTF-8 sequence.
then i resave XML file use UTF-8.but a new problem birth.like this:
:app:dataBindingProcessLayoutsDebug
line 1:0 mismatched input '?' expecting {COMMENT, SEA_WS, '<', PI}
Error:Execution failed for task ':app:dataBindingProcessLayoutsDebug'.
java.lang.NullPointerException (no error message)
<?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>
I have the same problem, and I finally found the solution.
I found that there is a layout xml file was written like that:
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text='@{"年龄 " + String.valueOf(user.age)}'/>
and then it cannot built on Windows platform, but it can built on Mac OS X platform, I think its a bug of Android Data Binding, so my temporary solution is:
don't writing any character in @{}
section, use string reference instead. (in my case, its replace as android:text='@{ @string/age_text + String.valueOf(user.age) }'/>
)
hope it helps you.
I also had this error. In my case I there was a redundant xml header at the bottom of a layout file.
Try removing the whitespace (or removing the header), changing:
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
to...
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
I had the same kind of problem with this log:
line 1:0 extraneous input '' expecting {COMMENT, SEA_WS, '<', PI}
This was super strange to me, no real feedback. To solve it:
Suffered the same problem for one day, finally found out the root cause. Andoid gradle plugin does not handle the encoding with Byte order mark (BOM) well. It is a encoding reading problem. If the file is saved in UTF-8 BOM format, Android gradle tool will detect the encoding as “UTF-8” with UniversalDetector library. The class android.databinding.tool.store.LayoutFileParser
will read like this:
InputStreamReader reader = new InputStreamReader(fin, “UTF-8”);
The first character returned by reader.read()
is 0xfeff
. Yes it is the '?' in error message line 1:0 mismatched input '?' expecting {COMMENT, SEA_WS, '<', PI}
line 1:0 mismatched input '?' expecting {COMMENT, SEA_WS, '<', PI}
.
Refer the magic number of BOM at https://en.wikipedia.org/wiki/Byte_order_mark
How UniversalDetector works at http://chardet.readthedocs.io/en/latest/how-it-works.html
Same situation! My colleagues have no troubles with project on Linux and Mac, but I couldn't built it on Windows.
Finally after 3 days trying to localise exception, I've found 2 layouts causes an error.
In my case trouble was with big cyrillic symbol "И" in android:text
attribute databinding layout.
I was getting this error:
line 1:0 mismatched input '?' expecting {COMMENT, SEA_WS, '<', PI}
And, I solved it by removing
<?xml version="1.0" encoding="utf-8"?>
this line from the top of my xml file.
Please note that I'm using viewBinding not dataBinding
buildFeatures{
viewBinding true
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.