Android数据绑定-找不到类android.view.data [英] android databinding - cannot find class android.view.data
本文介绍了Android数据绑定-找不到类android.view.data的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图在我的android应用中实现数据绑定,但是我遇到了这个问题:
I'm trying to implement databinding in my android app, however I'm stuck with this issue:
java.lang.ClassNotFoundException :找不到类 android.view.data
我的布局文件如下:
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.myapp.views.fragments.LocationSearchFragment">
<!-- data setup -->
<data>
<variable name="location"
type="com.myapp.models.Address" />
</data>
</LinearLayout>
</layout>
我用以下命令更新了 build.gradle
文件以下行:
I updated my build.gradle
file with following lines:
dataBinding {
enabled = true
}
如文档所建议: https://developer.android.com/topic/libraries/data-binding/index.html 。我正在运行最新版本的Android Studio。
As the documentation suggested: https://developer.android.com/topic/libraries/data-binding/index.html . I'm running the most recent version of Android Studio.
推荐答案
您需要放入 data
定义在 LinearLayout
之外:
You need to put your data
definition outside of your LinearLayout
:
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<!-- data setup -->
<data>
<variable name="location"
type="com.myapp.models.Address" />
</data>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.myapp.views.fragments.LocationSearchFragment">
</LinearLayout>
</layout>
这篇关于Android数据绑定-找不到类android.view.data的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文