Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android

Orcan Tiryakioğlu
Orcan Tiryakioğlu
2,604 Points

"Multiple root tags" error

Hi,

My problem is about extra credit task in "Exploring the Master-Detail Template" which says "Add another TextView to this file that displays mItem.content in addition to mItem.description." When I add another TextView to fragment_blogpost_detail.xml, Android Studio gives "Multiple root tags" error. It is also does not allow me to adding TextView in Design section. I also added a line inside the onCreateView() method in BlogPostDetailFragment.java for new TextView. What is the problem and what can I do for multiple TextViews?

Many thanks.

XML file:

<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/blogpost_detail"
    style="?android:attr/textAppearanceLarge"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:padding="16dp"
    android:textIsSelectable="true"
    tools:context=".BlogPostDetailFragment" />

<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/blogpost_content"
    style="?android:attr/textAppearanceLarge"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:padding="16dp"
    android:textIsSelectable="true"
    tools:context=".BlogPostDetailFragment" />

2 Answers

Wrap your TextView elements around this:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="vertical"
              android:layout_width="match_parent"
              android:layout_height="match_parent">

    <!-- TextView elements here -->

</LinearLayout>

Paste in your fragment_blogpost_detail.xml. You have an issue with the XML file.