2013-06-24 62 views
0

我是新來的android開發,並正在讀它的書(開始android 4開發),同時創建hello世界我陷入了一些錯誤,首先我解決了他們,但我的應用程序是強制關閉所以我複製粘貼的所有事情,並得到了4個錯誤: -錯誤在你好世界xml

Multiple annotations found at this line: - Attribute is missing the Android namespace prefix - Suspicious namespace: should start with http:// - Open quote is expected for attribute "xmlns:android" associated with an element type "LinearLayout". - error: Error parsing XML: not well-formed (invalid token)

Unexpected namespace prefix "android" found for tag TextView

Multiple annotations found at this line: - Unexpected namespace prefix "android" found for tag TextView - Attribute is missing the Android namespace prefix

Unexpected namespace prefix "android" found for tag Button

代碼示例

<?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:layout_orientation="vertical" 

<TextView 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/hello" /> 

<TextView 
    android:layout_width=」fill_parent」 
    android:layout_height=」wrap_content」 
    android:text=」@string/This is my first Android Application!」 /> 

<Button 
    android:layout_width="fill_parent" 
    android:layout_width="wrap_content" 
    android:text="@string/And this is clickable :D" /> 

我不認爲有一個在代碼中的任何錯誤:/

+0

是上述xml相同,在書中,我真的懷疑這一點。 – Thalaivar

回答

0

用」並使用ctr + sift + f替換每行代碼的引號並保存該文件。

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

    <TextView 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/hello" /> 

<TextView 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/This is my first Android Application!" /> 

<Button 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/And this is clickable :D" /> 

</LinearLayout> 
+0

我替換了所有的引號,但仍然得到相同的錯誤:( –

+0

嘗試我的代碼現在編輯上面的代碼 –

1

這是一個複製粘貼問題。將第2行中的引號替換爲「並且它應該可以工作

+0

仍然得到相同的錯誤沒有幫助:/ –

+0

刪除第2行「res /」和「android」之間的空格 字符串名稱不能有空格。對於所有的android:文本屬性刪除「@字符串/」 – Mus

0

替換」與 「」 在你的XML,使之成爲有效的XML

0
apk/res/ android 

刪除這裏的空間,使用

apk/res/android 
0

@string資源應該在字符串中聲明。 xml,試試這個!並閱讀更多

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

    <TextView 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="hello" /> 

    <TextView 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="This is my first Android Application!" /> 

    <Button 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="And this is clickable :D" /> 

    </LinearLayout>