Home > database >  I keep getting these errors "Multiple root tags" and "cannot resolve class" whil
I keep getting these errors "Multiple root tags" and "cannot resolve class" whil

Time:05-11

when try to close the nested LinearLayout in the main LinearLayout it takes like the close belongs to the main LinearLayout and the rest of the code after the second LinearLayout (TextView, TextView and Button) does not work and appear the errors Multiple root tags and Cannot resolve class (TextView, TextView and Button) , can anyone help me please?

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

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="16dp"
        android:layout_marginTop="16dp"
        android:layout_marginBottom="16dp"
        android:text="quantity"
        android:textAllCaps="true" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" />
    

        <Button
            android:layout_width="48dp"
            android:layout_height="48dp"
            android:layout_marginStart="16dp"
            android:layout_marginTop="16dp"
            android:layout_marginRight="8dp"
            android:backgroundTint="@android:color/holo_green_light"
            android:onClick="decrement"
            android:text="-"
            android:textSize="24sp" />

        <TextView
            android:id="@ id/quantity_text_view"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="16dp"
            android:text="0"
            android:textColor="@android:color/black"
            android:textSize="16sp" />

        <Button
            android:layout_width="48dp"
            android:layout_height="48dp"
            android:layout_marginLeft="8dp"
            android:layout_marginTop="16dp"
            android:backgroundTint="@android:color/holo_green_light"
            android:onClick="increment"
            android:text=" "
            android:textSize="24sp" />

    
    </LinearLayout>    

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="16dp"
        android:layout_marginTop="16dp"
        android:layout_marginBottom="16dp"
        android:text="price"
        android:textAllCaps="true" />

    <TextView
        android:id="@ id/price_text_view"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="16dp"
        android:text="$0"
        android:textColor="@android:color/black"
        android:textSize="16sp" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="16dp"
        android:layout_marginTop="16dp"
        android:backgroundTint="@android:color/holo_green_light"
        android:onClick="submitOrder"
        android:text="order" />


</LinearLayout>

CodePudding user response:

Thats because you have self closed the 2nd LinearLayout and then below you have made it like container so the below code is not included in the linear block code !!

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" />

you should not close it like this is should be like

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >

Here Is The Full Code

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

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="16dp"
        android:layout_marginTop="16dp"
        android:layout_marginBottom="16dp"
        android:text="quantity"
        android:textAllCaps="true" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >


    <Button
        android:layout_width="48dp"
        android:layout_height="48dp"
        android:layout_marginStart="16dp"
        android:layout_marginTop="16dp"
        android:layout_marginRight="8dp"
        android:backgroundTint="@android:color/holo_green_light"
        android:onClick="decrement"
        android:text="-"
        android:textSize="24sp" />

    <TextView
        android:id="@ id/quantity_text_view"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="16dp"
        android:text="0"
        android:textColor="@android:color/black"
        android:textSize="16sp" />

    <Button
        android:layout_width="48dp"
        android:layout_height="48dp"
        android:layout_marginLeft="8dp"
        android:layout_marginTop="16dp"
        android:backgroundTint="@android:color/holo_green_light"
        android:onClick="increment"
        android:text=" "
        android:textSize="24sp" />


    </LinearLayout>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginBottom="16dp"
android:text="price"
android:textAllCaps="true" />

<TextView
android:id="@ id/price_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:text="$0"
android:textColor="@android:color/black"
android:textSize="16sp" />

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:backgroundTint="@android:color/holo_green_light"
android:onClick="submitOrder"
android:text="order" />


</LinearLayout>
  • Related