Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android Build a Blog Reader Android App Rebuilding from Scratch Handling a Lack of Data

Nick Miller
Nick Miller
4,417 Points

XML Parsing Error

For the following code...

<TextView android:id="@android:id/empty"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="No items to display!" >
</TextView>

... I am receiving this error: "error:Error parsing XML: not well formed (invalid token)"

Since I can't build my project with this error, I can't move forward with the lessons.

Any idea what's going on here?

4 Answers

Daniel Hartin
Daniel Hartin
18,106 Points

The code you've posted looks okay a couple of things that I would suggest although only a guess.

Is the layout a relative layout as the align parent left and align parent top only apply to a relative layout. Also as the width is set to match_parent. The align left line is redundant I would remove this.

It may be better if you could post the entire XML code please.

Thanks Daniel

Nick Miller
Nick Miller
4,417 Points

Hi Daniel

Thanks for answering! Here's the full XML code:

<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="guru.NickMiller.blogreader.MainListActivity" >

    <ListView
        android:id="@android:id/list"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true" >
    </ListView>

    <TextView android:id="@android:id/empty"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:text="No items to display!" 
    </TextView>

</RelativeLayout>
Nick Miller
Nick Miller
4,417 Points

I'm still struggling with getting this to work. Any help is greatly appreciated.

Daniel Hartin
Daniel Hartin
18,106 Points

Hi Nick

Sorry I didn't get back to you sooner I must of missed the notification from treehouse.

I've just pasted the code straight into a dummy layout and it works fine apart from a missing > (See below for amendment)

android:text="No items to display!">

This was there on your original code post though I so assume something else is a miss however. Can you just try this first please to remove the error from the missing ">" and double check this doesn't resolve the problem (after saving changes of course so it takes effect)

Thanks Daniel