2013-12-20 33 views
-1

好吧,我剛開始學習如何開發一個應用程序,我做了正確的事情(或所以我希望)通過看看和學習從android本身。我花了在網絡上四處尋找了一段時間,沒能找到一個問題,這個早期的tutorialXml不好Formad錯誤

的答案,但是我甚至不能讓過去的教訓的第三部分,因爲它使想出一個錯誤。

這裏是我的參考代碼:

主要活動

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="horizontal" 
    <EditText 
     android:id="@+id/edit_message" 
     android:layout_weight="1" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:hint="@string/edit_message" 
     android:inputType="text" /> 
    <Button 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="@string/button_send" /> 
</LinearLayout> 

和strings.xml中

<?xml version="1.0" encoding="utf-8"?> 
<resources> 
    <string name="app_name">My First App</string> 
    <string name="action_settings">Settings</string> 
    <string name="edit_message">Enter a message</string> 
    <string name="button_send">Send</string> 
</resources> 

特定錯誤即時得到的是:「錯誤:錯誤解析XML:不格式正確(無效令牌)activity_main.xml/MyFirstApp/res/layout line 6 Android AAPT問題「

+0

你錯過了,收你的第一個項目在'xml':在'LinearLayout' – Fllo

+2

你不應該使用智障字。 – user1336827

+2

這是我們的基本問題...我們需要先學習xml和java,然後再跳到android開發。直到他不知道如何使用劍和盾,才能贏得戰爭。 –

回答

3
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="horizontal" > <!-- you forgot this ">" --> 
<EditText 
    android:id="@+id/edit_message" 
    android:layout_weight="1" 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:hint="@string/edit_message" 
    android:inputType="text" /> 
<Button 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="@string/button_send" /> 
</LinearLayout> 

Error parsing XML means that there is an error in your xml files
not well-formed your files have something wrong in its build
activity_main.xml which xml
/MyFirstApp/res/layout where in my package
line 6 you know everything ;)

希望這會有所幫助。

2

更改此:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="horizontal" 

有了這個:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="horizontal" > 
+1

他用「>」結束了聲明,就像我應該做的那樣。 – Kthraa

+0

耶...看到..非常微小的語法錯誤。 –