Configurations for content_main.xml must agree on the root element's ID

Viewed 32

I am trying to add a fragment into a frame layout on a landscape view, but the runtime keeps coming back with: Configurations for content_main.xml must agree on the root element's ID.

Missing ID:

  • layout-land

@+id/fragment:

  • layout

I can't seem to figure this one out, and it is frustrating. Full XML for fragment and Linear layout below:

 <?xml version="1.0" encoding="utf-8"?>

<fragment
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/fragment"
android:name="com.example.tasktimer.MainActivityFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:layout="@layout/fragment_main"
/>

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:weightSum="2"
app:layout_behavior="@string/appbar_scrolling_view_behavior">

<fragment
    android:id="@+id/fragment"
    android:name="com.example.tasktimer.MainActivityFragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="1"
    tools:layout="@layout/fragment_main" />

<FrameLayout
    android:id="@+id/task_details_container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="1"/>


 </LinearLayout>
1 Answers

You have two editions of content_main.xml:

  • res/layout/content_main.xml
  • res/layout-land/content_main.xml

The root XML element for those need to have an android:id attribute with the same value (perhaps for use with data binding or view binding). In your case, apparently they do not.

If your code snippet is supposed to be showing those two layout resources:

  • One has a <fragment> as the root element, and it has android:id="@+id/fragment"

  • The other has a <LinearLayout> as the root element, and it does not appear to have an android:id value, which does not match

Related