1

我是 android 编程新手,最近在我的 ubuntu 系统上安装了 Eclipse junos 和 ADT 插件,并下载了 android SDK。在此之后,我创建了一个 android 项目,默认情况下是 hello world 程序,当我运行这个程序时,我收到一个错误“XML 文件中的错误:正在中止构建。”。但我没有编辑任何代码。请帮我解决这个问题。下面是程序。我还收到一个错误,说 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;
    }
}

这是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>
4

2 回答 2

1
<RelativeLayout xmlns:android="schemas.android.com/apk/res/android"; xmlns:tools="schemas.android.com/tools"; 

上面的分号似乎是问题尝试删除它们

于 2012-10-23T07:02:51.063 回答
0

尝试这个

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

您的 xml 文件中有额外的分号。

还要确保你的 xml 的第一行是

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

所以你完整的 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>
于 2012-10-23T07:00:33.640 回答