android – 没有XML内容.请在文档中添加根视图或布局

我正在开发一个Android应用程序.我是XML的新手.我收到的消息是“没有XML内容.请在文档中添加根视图或布局”下面给出了XML代码.请帮忙

<?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>

—-主要活动代码

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.

解决方法:

哦 – 看到’main.out.xml’?当你用eclipse启动XML文件时会发生什么.只需删除’out’xml并保留main.xml

当你点击Play时,一定要选择/编辑.java文件,否则eclipse会产生’out.xml’而无法启动.

相关文章

Android性能优化——之控件的优化 前面讲了图像的优化,接下...
前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要...
最近项目重构,涉及到了数据库和文件下载,发现GreenDao这个...
WebView加载页面的两种方式 一、加载网络页面 加载网络页面,...
给APP全局设置字体主要分为两个方面来介绍 一、给原生界面设...
前言 最近UI大牛出了一版新的效果图,按照IOS的效果做的,页...