每当我尝试构建在Android Studio中一直在使用的应用程序时,都会遇到相同的错误,即“找不到符号类ImageLayoutBindingImpl”。

到目前为止,我尝试过的事情是重新构建,清理和重新构建,删除映射器文件并重新构建,以及使用Invalidate Caches / Restart选项。我也曾尝试删除ImageLayoutBinding和DataBinderMapperImpl,同样无济于事。

完整的错误消息如下:

Found data binding errors.
****/ data binding error ****msg:Identifiers must have user defined types
from the XML file. image is missing it file:D:\Arianwen\Documents\TouristApp\app\src\main\res\layout\image_layout.xml
loc:30:35 - 30:39
****\ data binding error ****

编辑:根据要求,我的image_layout.xml文件,实际文档中不存在问号之前的空格,并且该位置可以阻止数据段消失到Stack Overflow后端中。
< ?xml version="1.0" encoding="utf-8"?>
    <layout>
        <data>
            <variable
                name="image"
                type="com.example.iamatourist.Image" />
        </data>

    <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

        <GridLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:columnCount="3"
        android:rowCount="3"
        tools:ignore="UselessParent">

            <ImageView
            android:id="@+id/photoView"
            android:layout_width="@dimen/image_size"
            android:layout_height="@dimen/image_size"
            android:layout_row="0"
            android:layout_rowSpan="2"
            android:layout_column="0"
            android:layout_columnSpan="3"
            android:contentDescription="@string/image_desc"
            tools:srcCompat="@drawable/ic_photo_large" />

            <ImageButton
            android:id="@+id/fav_button_img"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_row="1"
            android:layout_column="0"
            android:background="@color/transparent"
            android:contentDescription="@string/fav_button_off"
            android:elevation="2dp"
            tools:srcCompat="@drawable/ic_favorite_border_white_50percent" />

            <ImageButton
            android:id="@+id/options_button_img"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_row="1"
            android:layout_rowSpan="2"
            android:layout_column="2"
            android:layout_gravity="bottom|end"
            android:background="@color/transparent"
            android:contentDescription="@string/options_desc"
            android:elevation="2dp"
            app:menu="@menu/image_options_menu"
            tools:srcCompat="@drawable/ic_image_menu" />

            <TextView
            android:id="@+id/img_title"
            android:layout_width="140dp"
            android:layout_height="wrap_content"
            android:layout_row="2"
            android:layout_column="0"
            android:layout_columnSpan="2"
            android:text="@{image.title}" />

        </GridLayout>
    </FrameLayout>
</layout>

最佳答案

如您的错误所示

 msg:Identifiers must have user defined types from the XML file.
 image is missing it file:D:\Arianwen\Documents\TouristApp\app\src\main\res\layout\image_layout.xml

您已将image用作image_layout.xml文件中的变量,但未在<Data>标记中定义。

07-24 09:37
查看更多