Daniele C Daniele C - 6 months ago 218
Android Question

Multiple root tags error

I'm new to Android development and programming in general. I tried to write some layout code but I'm getting

Multiple root tags error


Anyone who can help me?

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

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

<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />

<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="This is my first android app!" />

<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Button!" />

</LinearLayout>




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

<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Hello!" />

<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="This is my first android app!" />

<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Button!" />

</LinearLayout>


I was able to fix it this way, but it doesn't work if in the first TextView text I put "@string/Hello" can someone tell me why?

Answer

try this:

<?xml version="1.0" encoding="utf-8"?>
 <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/hello" />

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="This is my first android app!" />

    <Button
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Button!" />

    </LinearLayout>