Android binding error: execution failed for task ': app: dataBindingProcessLayoutsDebug'

my partner in our project used android databinding.in my computer had an error, but there was no error in his mac.i cannot solve this program. please help !! this is my gradle assembly:

dataBinding {
    enabled = true
}

the first line of androidstudio says

com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException:       Invalid byte 2 of 2-byte UTF-8 sequence.

then I save the XML file using UTF-8. but this is a new problem. In a similar way:

: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>  
+4
source share
4 answers

I have the same problem and I finally found a solution.
I found that the xml layout file was written as follows:

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text='@{"年龄 " + String.valueOf(user.age)}'/>

Windows, Mac OS X, , Android, :
@{}, . ( android:text='@{ @string/age_text + String.valueOf(user.age) }'/>)
, .

+6

:

line 1:0 extraneous input '' expecting {COMMENT, SEA_WS, '<', PI}

, . :

  • ,
  • .
+1

, , . gradle (BOM). . UTF-8, Android gradle "UTF-8" UniversalDetector. android.databinding.tool.store.LayoutFileParser :

InputStreamReader reader = new InputStreamReader(fin, "UTF-8");

, reader.read(), 0xfeff. , ? line 1:0 mismatched input '?' expecting {COMMENT, SEA_WS, '<', PI}.

https://en.wikipedia.org/wiki/Byte_order_mark

UniversalDetector http://chardet.readthedocs.io/en/latest/how-it-works.html

+1
source

I also had this error. In my case, I had a redundant XML header at the bottom of the layout file.

Try removing the spaces (or removing the title) by 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"
0
source

Source: https://habr.com/ru/post/1626616/


All Articles