1

I am trying to follow this tutorial : http://developer.android.com/training/basics/firstapp/building-ui.html as I am new to android developing and this is what my "activity_main.xml" file looks like :

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

<EditText android:id="@+id/edit_message"
    android:layout_weight="1"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:hint="@string/edit_message" />

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/button_send" />

When I click run I get an error that says "No XML content. Please add a root view or layout to your document." and I noticed there is a new file generated called "activity_main.out.xml". What could I be doing wrong?

bmargulies
  • 97,814
  • 39
  • 186
  • 310
ez4nick
  • 9,756
  • 12
  • 37
  • 69

5 Answers5

3

You're probably seeing this when you have your layout (activity_main.xml) open in the editor and click the "run" button in the toolbar. There are two ways to work around this:

  1. Click the drop-down next to the run button and select your project from the list, or
  2. Switch the editor to a code file and then click the run button.
3

In addition to Torgis's reply (if you are using a Macbook Retina and most likely get this error with the ADT Preview 21) - the workaround would be to switch to XML view and right click, go to Source > Cleanup Document > Check the Fix XML Declaration and make the changes.

Once back in Graphical Layout view, it should work as expected.

If clean up document is not enabled, just format the code and check for the changes.

3

Eclipse is running the XML not your activity. If previous solution doesn't work then delete actvity_main_out.xml and run the app not XML.

Echilon
  • 10,064
  • 33
  • 131
  • 217
raul
  • 31
  • 1
2

Just delete activity_main.out.xml and run project again. Be sure, that you switched on .java perspective, not .xml

[UPDATE] Fixed in Eclipse Juno

Geralt_Encore
  • 3,721
  • 2
  • 31
  • 46
0

I'd like to point out that there is a bug in ADT Preview 21 - I installed Preview Tools to fix the MacBook Retina emulator bug here: Android Emulator do not scale to 100% for Mac Book Pro with Retina Display.

However, I cannot open any of my layouts now because they all give me this error. I found that there is a workaround: switch to XML view and make any edit - even if it's a single space. Save, and then switch back to graphical layout, and the error is gone.

Community
  • 1
  • 1
AWT
  • 3,657
  • 5
  • 32
  • 60