2012-02-03 87 views
3

我只是試圖運行這裏的教程http://developer.android.com/resources/tutorials/hello-world.html,特別是我們添加字符串資源的部分。我複製的代碼,但我發現了以下錯誤......Android string.xml錯誤

[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); 
    } 
} 

此外, 「乾淨」 沒有工作,但是這是一個好主意。

+0

解決了這個問題複製代碼,並用它工作的罰款與我我可以看看你的java文件? – Akram 2012-02-03 05:37:56

+0

你做了一個乾淨的項目嗎?有時會解決這樣的奇怪的東西。 – 2012-02-03 05:40:02

+0

好吧,我不知道,但我再次複製,一切似乎工作。它可能是某種流浪的角色,在那裏或類似的? – slabounty 2012-02-03 17:46:54

回答

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