Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple root tags in Android Studio [duplicate]

I am edit my fragment_main.xml in Android Studio, and I am getting this error:

Multiple Root Tags

The code block in question here is:

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

</LinearLayout>
<EditText   <!--Error here in the bracket-->
android:id="@+id/edit_message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="@string/edit_message" />
<Button    <!--Error here in the bracket-->
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/button_send"/>

I am getting the errors in the brackets before EditText and before Button

like image 331
rakeshdas Avatar asked Jun 18 '14 00:06

rakeshdas


1 Answers

Since in Android every xml file there must be only one root layout. Just add the EditText and Button inside the LinearLayout. Right code is shown below

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

    <EditText  
        android:id="@+id/edit_message"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:hint="@string/edit_message" />

    <Button    
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/button_send" />

</LinearLayout>
like image 110
Anil Jadhav Avatar answered Oct 04 '22 15:10

Anil Jadhav