Solace
Solace

Reputation: 9020

Android XML layout: Error parsing XML: not well-formed (invalid token) - I did close my View tags

I am getting this error on the Button view. From the many questions I saw on SO, it seems that this error arises when you don't close your views properly.

I think I have closed all the tags properly but still getting this error. Why is that?

<RelativeLayout 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"
    tools:context="${relativePackage}.${activityClass}" >

    <Button 
        android:layout_width="wrap_content"
        android:layout:height="wrap_content"
        android:text="@string/mainActivity_button1"
        android:onClick="startSecondActivity" />

</RelativeLayout>

Upvotes: 0

Views: 2180

Answers (3)

Pratik Dasa
Pratik Dasa

Reputation: 7439

Its ofcourse typo on this line :

android:layout:height="wrap_content"

replace above line with :

android:layout_height="wrap_content"

Upvotes: 1

Naveen Tamrakar
Naveen Tamrakar

Reputation: 3339

<Button 
        android:layout_width="wrap_content"
        android:layout:height="wrap_content"
        android:text="@string/mainActivity_button1"
        android:onClick="startSecondActivity" />

Replace : in an attribute name.

<Button 
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/mainActivity_button1"
    android:onClick="startSecondActivity" />

Upvotes: 2

laalto
laalto

Reputation: 152927

There's an additional/typo : in an attribute name.

Replace

android:layout:height

with

android:layout_height

The error is not only about unclosed tags but XML syntax problems in general. In XML, you can have only one namespace prefix for an attribute, and namespace prefixes are separated from the name with :.

Upvotes: 2

Related Questions