简体   繁体   English

XML文件错误。 Android编程

[英]Error in XML file. Android programming

I am new to android programming and recently installed Eclipse junos and ADT plugin on my ubuntu system and downloaded the android SDK. 我是android编程的新手,最近在ubuntu系统上安装了Eclipse junos和ADT插件,并下载了android SDK。 After this, i created an android project, which by default is the hello world program, when i run this program i got an error "Error in an XML file: aborting build.". 此后,我创建了一个android项目,默认情况下是hello world程序,当我运行该程序时,出现错误“ XML文件中的错误:正在中止构建。”。 But i haven't edited any code. 但是我还没有编辑任何代码。 Please help me solve this problem. 请帮我解决这个问题。 Below is the program. 下面是程序。 I get an error also saying R cannot be resolved to a variable. 我也收到一条错误消息,说R无法解析为变量。

package com.example.myandroid;

import android.os.Bundle;

import android.app.Activity;

import android.view.Menu;

public class MainActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }
}

Here is the activity_main.xml 这是activity_main.xml

  <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:tools="schemas.android.com/tools"
 android:layout_width="match_parent"
 android:layout_height="match_parent" >
    <TextView android:layout_width="wrap_content" 
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true" 
            android:layout_centerVertical="true" 
            android:text="@string/hello_world" 
            tools:context=".MainActivity" /> 
</RelativeLayout>
<RelativeLayout xmlns:android="schemas.android.com/apk/res/android"; xmlns:tools="schemas.android.com/tools"; 

上面的分号似乎是问题,尝试将其删除

Try this 尝试这个

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:tools="schemas.android.com/tools"
     android:layout_width="match_parent"
     android:layout_height="match_parent" >
        <TextView android:layout_width="wrap_content" 
                android:layout_height="wrap_content"
                android:layout_centerHorizontal="true" 
                android:layout_centerVertical="true" 
                android:text="@string/hello_world" 
                tools:context=".MainActivity" /> 
    </RelativeLayout>

You have extra semi colons in your xml file. 您的xml文件中有多余的分号。

Also make sure the first line of your xml is 还要确保xml的第一行是

<?xml version="1.0" encoding="utf-8"?>

So your complete xml should look like 因此,您完整的xml应该看起来像

    <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
    <TextView android:layout_width="wrap_content" 
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true" 
        android:layout_centerVertical="true" 
        android:text="@string/hello_world" 
        tools:context=".MainActivity" /> 
</RelativeLayout>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM