Brian
Brian

Reputation: 13

Unexpected token error?

I am coding for a class and nested a linear layout horizontal within a linear layout vertical.

Now android studio is not recognizing the closing tag resulting in an unexpected token error and I'm getting a root tag error for every element that comes after the nested layout.

I checked it against the teacher's code and it appears to be the exact same.

I'm sure it's something very simple that I'm missing. Any ideas?

My code:

 `<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:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:orientation="vertical"
    android:paddingBottom="@dimen/activity_vertical_margin"
    tools:context=".MainActivity">

    <TextView
        android:text="Quantity"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        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_marginTop="16dp"
            android:onClick="decrement"
            android:text="-"/>

        <TextView
            android:text="2"
            android:textColor="@android:color/black"
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:layout_marginRight="8dp"
            android:layout_marginLeft="8dp"
            android:textSize="16sp" />

        <Button
            android:layout_width="48dp"
            android:layout_height="48dp"
            android:onClick="increment"
            android:text="+"/>

    </LinearLayout>

    <TextView        <---getting multiple root tag error
        android:text="Price"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAllCaps="true"
        android:layout_marginTop="16dp"/>

    <TextView        <---getting multiple root tag error
        android:text="$10"
        android:textColor="@android:color/black"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:textSize="16sp"
        android:layout_marginTop="16dp"/>

    <Button     <---getting multiple root tag error
        android:layout_marginTop= "16dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="ORDER"
        android:onClick="submitOrder" />

</LinearLayout>   <---getting unexpected token error`

Upvotes: 0

Views: 1172

Answers (1)

SaNtoRiaN
SaNtoRiaN

Reputation: 2202

The error is here

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"/> <-- this is the error

you should use instead

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

Upvotes: 3

Related Questions