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