2

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.

2 Answers 2

6

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>
Sign up to request clarification or add additional context in comments.

Comments

2

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>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.