0

I'm trying to have the ImageView appear based on where the user taps in the GameView. I'm getting an error on android:layout_height="300dp" with the message "Error:(15) error: not well-formed (invalid token)." GameView extends ViewGroup. I have onMeasure, onLayout, and onDraw implemented for GameView.

Hovering at the end of these lines shows these error hints:

<com.example.GameView -- Multiple root tags

android:layout_height="300dp" -- Tag start is not closed

<ImageView -- Multiple root tags

<com.example.GameView> -- Unexpected tokens

</LinearLayout> -- Unexpected tokens

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

    <com.example.GameView
        android:layout_width="match_parent"
        android:layout_height="300dp"

        <ImageView
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            />
        </com.example.GameView>

</LinearLayout>
stumped
  • 3,235
  • 7
  • 43
  • 76

3 Answers3

0

I think you have a syntax error. com.example.GameView isn't closed properly. Should be like this.

 <com.example.GameView
    android:layout_width="match_parent"
    android:layout_height="300dp">

    <ImageView
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        />
</com.example.GameView>
Zafer
  • 316
  • 4
  • 13
0
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"

You missed > of LinearLayout.

Tung Tran
  • 2,885
  • 2
  • 17
  • 24
0

The final layout should look like the following.

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

    <com.example.GameView
        android:layout_width="match_parent"
        android:layout_height="300dp">

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
    </com.example.GameView>

</LinearLayout>
Reaz Murshed
  • 23,691
  • 13
  • 78
  • 98