安卓string.xml错误

3
我只是想在这里运行教程,具体来自http://developer.android.com/resources/tutorials/hello-world.html,特别是我们添加字符串资源的部分。我已经复制了代码,但是我得到了以下错误...
[2012-02-02 20:35:35 - HelloAndoird] /home/slabounty/workspace/HelloAndoird/res/values/strings.xml:2: error: Found text "
[2012-02-02 20:35:35 - HelloAndoird] /" where item tag is expected"
[2012-02-02 20:35:35 - HelloAndoird] /home/slabounty/workspace/HelloAndoird/res/layout/main.xml:3: error: Error parsing XML: not well-formed (invalid token)

这是strings.xml文件。
<?xml version="1.0" encoding="utf-8"?>
  <resources>
    <string name="hello">Hello Android! I am a string resource!</string>
    <string name="app_name">Hello, Android</string>
  </resources>

如果需要访问main.xml,

<?xml version="1.0" encoding="utf-8"?>
<TextView 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/textview"   
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"  
    android:text="@string/hello"/>

我猜这是一些显而易见的东西,但我已经重新输入和复制了几次,并删除了字符串标签前面的空格,但错误仍然存在。
有任何想法吗?
编辑... 这是Java文件...
package com.example.helloandroid;

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


public class HelloAndoirdActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }
}

此外,“clean”没有起作用,但这是个好主意。

你的代码我已经复制并使用了,运行得很好。能否让我看一下你的Java文件? - Akram
你做了项目清理吗?有时候这样可以解决奇怪的问题。 - Kevin Qiu
好的,我不知道是怎么回事,但我又复制了一遍,现在似乎一切正常了。可能是某个奇怪的字符或类似的东西进去了? - slabounty
2个回答

0

为了保险起见,将你的TextView包裹在这样的布局中:

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

        <TextView
            android:id="@+id/textView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/hello" />

    </LinearLayout>   

然而我不明白为什么你的代码会遇到麻烦。但我希望这可以解决你的问题。


-1

我通过更改解决了这个问题。

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

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接