3

I am developing an android application. And i am new to XML. I am getting the message saying "No XML content. Please add a root view or layout to your document" The XML code is given below. Please help

<?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="vertical" >

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/ref" 
        android:textSize="15dp"/>
    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/ref2" 
        android:textSize="15dp"/>

    <EditText
        android:id="@+id/uname"
        android:layout_width="150dp"
        android:layout_height="25dp"
        android:inputType="text"
        android:ems="5" >

        <requestFocus />
    </EditText>

   <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/ref3" 
        android:textSize="15dp"/>

    <EditText
        android:id="@+id/pwd"
        android:layout_width="150dp"
        android:layout_height="25dp"
        android:inputType="text"
        android:ems="5" />

    <Button
        android:layout_width="60dp" 
        android:layout_height="35dp"
        android:text="@string/ref" 
        android:id="@+id/bLogin" />
  </LinearLayout>

----Main Activity Code---

package com.android.disasterAlertApp;

import android.app.Activity;
import android.os.Bundle;
import android.widget.Button;

public class MainActivity extends Activity {
   /** Called when the activity is first created. */
   Button login;
   @Override
   public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    login =(Button) findViewById(R.id.bLogin);
   }
}

----Manifest----
[2012-04-17 00:34:20 - Disaster Alert App] res\layout\main.xml:0: error: Resource entry      main is already defined.
[2012-04-17 00:34:20 - Disaster Alert App] res\layout\main.out.xml:0: Originally defined here.
[2012-04-17 00:34:20 - Disaster Alert App] C:\Users\Acer\workspace\Disaster Alert App\res\layout\main.out.xml:1: error: Error parsing XML: no element found
[2012-04-17 01:05:59 - Disaster Alert App] res\layout\main.xml:0: error: Resource entry main is already defined.
[2012-04-17 01:05:59 - Disaster Alert App] res\layout\main.out.xml:0: Originally defined here.
[2012-04-17 01:05:59 - Disaster Alert App] C:\Users\Acer\workspace\Disaster Alert App\res\layout\main.out.xml:1: error: Error parsing XML: no element found
[2012-04-17 01:11:14 - Disaster Alert App] res\layout\main.xml:0: error: Resource entry main is already defined.
[2012-04-17 01:11:14 - Disaster Alert App] res\layout\main.out.xml:0: Originally defined here.
[2012-04-17 01:11:14 - Disaster Alert App] C:\Users\Acer\workspace\Disaster Alert App\res\layout\main.out.xml:1: error: Error parsing XML: no element found
[2012-04-17 01:14:56 - Disaster Alert App] ------------------------------
[2012-04-17 01:14:56 - Disaster Alert App] Android Launch!
[2012-04-17 01:14:56 - Disaster Alert App] Connection with adb was interrupted.
[2012-04-17 01:14:56 - Disaster Alert App] 0 attempts have been made to reconnect.
[2012-04-17 01:14:56 - Disaster Alert App] You may want to manually restart adb from the Devices view.
[2012-04-17 01:17:27 - Disaster Alert App] Error in an XML file: aborting build.
[2012-04-17 01:37:10 - Disaster Alert App] res\layout\main.xml:0: error: Resource entry main is already defined.
[2012-04-17 01:38:42 - Disaster Alert App] res\layout\main.xml:0: error: Resource entry main is already defined.
[2012-04-17 01:38:42 - Disaster Alert App] res\layout\main.out.out.xml:0: Originally defined here.
[2012-04-17 01:38:42 - Disaster Alert App] C:\Users\Acer\workspace\Disaster Alert App\res\layout\main.out.out.xml:1: error: Error parsing XML: no element found
[2012-04-17 01:39:28 - Disaster Alert App] Error in an XML file: aborting build.
Sindu_
  • 1,347
  • 8
  • 27
  • 67
  • When you post code make sure to do it in your Question (there is an edit button if needbe) Code doesn't get formatted in comments so it is much more difficult to follow. – FoamyGuy Apr 16 '12 at 20:31
  • Is your xml file called main.xml? and is it located in your res/layout/ folder? – FoamyGuy Apr 16 '12 at 20:31
  • I have posted the main activity and manifest.Yes that's right, that's the name and location of it. – Sindu_ Apr 16 '12 at 20:37

4 Answers4

11

Ohhh -- see the 'main.out.xml'? that's what happens when you launch an XML file with eclipse. just delete the 'out' xml and keep the main.xml

Be sure to select/be editing a .java file when you hit Play otherwise eclipse will spawn an 'out.xml' and fail to launch.

h4rpur
  • 341
  • 2
  • 6
  • 1
    looks like you've got multiples also, delete any file in your layout folder that has "out" in the name. This page has a fix that will stop the out.xml files from getting made: http://stackoverflow.com/questions/2393103/android-sdk-main-out-xml-parsing-error. Also that is not a Manifest...Manifest is in the android-manifest.xml file in your project root. read up here to learn more about them: http://developer.android.com/guide/topics/manifest/manifest-intro.html – FoamyGuy Apr 16 '12 at 20:42
  • Thanks for that, Tim - I have trained myself to switch off to a classfile to launch when editing XML's heavily and needing to test, after lots of frustration when I first ran into that bug. – h4rpur Apr 16 '12 at 20:45
1

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
1

just close eclipse and restart. That worked for me.

DigvijayG
  • 11
  • 2
0

Worked for me: In eclipse click help->check for updates. If you have updates available (Android stuff in particular) - install them.

Asaf Pinhassi
  • 15,177
  • 12
  • 106
  • 130