Szworny Dziąch Szworny Dziąch - 5 months ago 47
Android Question

android databinding - cannot find class android.view.data

I'm trying to implement databinding in my android app, however I'm stuck with this issue:

java.lang.ClassNotFoundException: Didn't find class "android.view.data"


My layout file looks like this:

<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>


I updated my
build.gradle
file with following lines:

dataBinding {
enabled = true
}


As the documentation suggested: https://developer.android.com/topic/libraries/data-binding/index.html . I'm running the most recent version of Android Studio.

Answer

Put the data outside of your LinearLayout.

Like this:

<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>
Comments