3

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?

1
  • add <layout> tag as root of your xml . Commented Sep 14, 2018 at 4:17

3 Answers 3

5

Data binding layout files are slightly different and start with a root tag of layout followed by a data element and a view root element

https://developer.android.com/topic/libraries/data-binding/expressions

You don't have a generic layout tag

Sign up to request clarification or add additional context in comments.

6 Comments

After fixing my original code, I get this error: > Cannot find the setter for attribute 'android:text' with parameter type V on android.widget.TextView This is for android:text="@{user.name}"
@battery You can manage to solve it by deleting .idea, .gradle and gradle folders and let Android Studio recreate the whole project from scratch from gradle files.
@RavindraKushwaha How would that help? Is this documented in any way somewhere?
@RavindraKushwaha I think you mean, "Is your problem solved?" And no, your suggestion has resulted in another error.
@battery From the docs, type="com.example.User"... Not sure why you have this "ObserableArrayMap" thing
|
3

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>

Comments

1

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.