Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Databinding error: Only one layout element and one data element are allowed.

I'm getting following error when using databinding and include tag inside:

Error:Execution failed for task ':app:dataBindingProcessLayoutsBetaDebug'.>data binding error msg:Only one layout element and one data element are allowed. [path to file] has 3file:[path to file]****\ data binding error **** 

This is my layout file:

[...]          <LinearLayout             android:id="@+id/activity_description_content"             android:layout_width="match_parent"             android:layout_height="wrap_content"             android:layout_alignParentTop="true"             android:orientation="vertical">              <include                 android:id="@+id/activity_description_header_bottom"                 layout="@layout/activity_description_header_bottom" />              <include                 android:id="@+id/activity_description_contact_info"                 layout="@layout/activity_description_contact_info" />              <include                 android:id="@+id/activity_description_other_info_box"                 layout="@layout/activity_description_other_info_box" />              <include                 android:id="@+id/activity_description_bottom_buttons"                 layout="@layout/activity_description_bottom_buttons" />         </LinearLayout> [...] </layout> 

And in each of the included layouts i have something like this:

<layout xmlns:android="http://schemas.android.com/apk/res/android"> [...] </layout> 

From this reply: Android Data Binding using include tag i suppose that my code is correct, why databinder thinks that I use more than single tag in the file?

like image 734
RMK Avatar asked Apr 09 '16 17:04

RMK


1 Answers

I solved my issue. This error appears when there is more than single element in the layout tag:

Wrong:

<layout>      <data>           ...      </data>      <LinearLayout>           ...      </LinearLayout>      <LinearLayout>           ...      </LinearLayout> </layout> 

Correct:

<layout>      <data>           ...      </data>      <LinearLayout>          <LinearLayout>               ...          </LinearLayout>          <LinearLayout>               ...          </LinearLayout>      </LinearLayout> </layout> 
like image 90
RMK Avatar answered Nov 08 '22 13:11

RMK