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

Viewed 2732

Here is my xml:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/a"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".ui.a.AFragment">
    <data>
        <import type="android.databinding.ObservableArrayMap"/>
        <variable name="user" type="ObservableArrayMap"/>
    </data>
    <TextView
        android:id="@+id/message"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@{user.name}"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

</android.support.constraint.ConstraintLayout>

I get the following error on running:

Caused by: android.view.InflateException: Binary XML file line #9: Binary XML file line #9: Error inflating class data Caused by: android.view.InflateException: Binary XML file line #9: Error inflating class data Caused by: java.lang.ClassNotFoundException: Didn't find class "android.view.data" on path: DexPathList[[zip file "/data/app/x.x.x-2/base.apk", zip file "/data/app/x.x.x-2/split_lib_dependencies_apk.apk", zip file "/data/app/x.x.x-2/split_lib_slice_0_apk.apk", zip file "/data/app/x.x.x-2/split_lib_slice_1_apk.apk", zip file "/data/app/x.x.x-2/split_lib_slice_2_apk.apk", zip file "/data/app/x.x.x-2/split_lib_slice_3_apk.apk", zip file "/data/app/x.x.x-2/split_lib_slice_4_apk.apk", zip file "/data/app/x.x.x-2/split_lib_slice_5_apk.apk", zip file "/data/app/x.x.x-2/split_lib_slice_6_apk.apk", zip file "/data/app/x.x.x-2/split_lib_slice_7_apk.apk", zip file "/data/app/x.x.x-2/split_lib_slice_8_apk.apk", zip file "/data/app/x.x.x-2/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/x.x.x-2/lib/arm, /system/lib, /vendor/lib]]

The error is on the <data> line (begin tag).

What is causing this error and how can I fix it?

3 Answers

Here is sample layout file. Modify your layout accordingly.

<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android">
   <data>
       <variable name="user" type="com.example.User"/>
   </data>
   <LinearLayout
       android:orientation="vertical"
       android:layout_width="match_parent"
       android:layout_height="match_parent">
       <TextView android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:text="@{user.firstName}"/>
       <TextView android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:text="@{user.lastName}"/>
   </LinearLayout>
</layout>

You need to use the following the things for the dataBinding in Android

First make sure , you are adding the dataBindinginside your build.gradle for the model.

android {
    compileSdkVersion 27
    defaultConfig {
        applicationId "YOUR_APPP"
        minSdkVersion 15
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"

    }

    dataBinding {
        enabled = true   //// This is need to be for the dataBinding
    }
    buildToolsVersion '27.0.3'
}

The second one inside your the build.gradle (Project) need to use the jcenter() entry inside the repositories

    allprojects {
        repositories {
            google()
            jcenter()
            maven { url "https://jitpack.io" }

        }
    }

    task clean(type: Delete) {
      delete rootProject.buildDir
    }

And the last one inside the layout.xml , you need to start and end tag using the layout tag like below

<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools">



    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center"
        android:padding="10dp"
        android:background="@drawable/splash"
        tools:context=".user.activity.SplashActivity">


         /**
          * USE YOUR ALL RESOURCES HERE
          */

    </RelativeLayout>
</layout>

For more understanding refer this site Reference site

Related