Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/kotlin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
关于Kotlin与视图模型的数据绑定_Kotlin - Fatal编程技术网

关于Kotlin与视图模型的数据绑定

关于Kotlin与视图模型的数据绑定,kotlin,Kotlin,在Kotlin中将数据绑定与视图模型一起使用时出现运行时错误 我的xml代码如下所示: inner class WordViewHolder(val binding: RecyclerviewItemBinding): RecyclerView.ViewHolder(binding.root) 运行时出现以下错误: e:[kapt]发生异常:android.databinding.tool.util.LoggedErrorException:发现数据绑定错误 请确保输入与您接收的数据相同的

在Kotlin中将数据绑定与视图模型一起使用时出现运行时错误

我的xml代码如下所示:

inner class WordViewHolder(val binding: RecyclerviewItemBinding):
RecyclerView.ViewHolder(binding.root)

运行时出现以下错误:

e:[kapt]发生异常:android.databinding.tool.util.LoggedErrorException:发现数据绑定错误


请确保输入与您接收的数据相同的名称,例如

<data >
    <variable name="wordData"
        type="com.example.android.roomwordssample.Word"/>
</data>

现在将变量名word替换为wordData,错误就解决了

<TextView
    android:id="@+id/textView"
    style="@style/word_title"
    android:text="@{word.word}"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@android:color/holo_orange_light" />

<TextView
    android:id="@+id/textView"
    style="@style/word_title"
    android:text="@{word.word}"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@android:color/holo_orange_light" />