Marek M.
Marek M.

Reputation: 3951

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.

Upvotes: 2

Views: 1241

Answers (2)

pierre-charles Mangin
pierre-charles Mangin

Reputation: 69

The data binding is never in the <LinearLayout>. You should put it in the the <layout> zone 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>

Upvotes: 2

earthw0rmjim
earthw0rmjim

Reputation: 19417

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>

Upvotes: 6

Related Questions