Multiple root tags in Android Studio

I edit my fragment_main.xml file in Android Studio and I get this error:

Multiple Root Tags

This block of code has:

<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 get errors in parentheses before EditText and before Button

+10
java android android-layout android-fragments
source share
1 answer

Since in Android, each XML file should have only one root layout. Just add EditText and Button inside LinearLayout. The correct 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> 
+13
source share

All Articles