2011-05-23 35 views
0

我從一本書構建了我的第一個Android程序。它不斷崩潰在一個XML文件上。我從書中下載了xml代碼,使用它,它運行良好!爲什麼我的XML代碼在與其他運行正常的XML代碼相同時崩潰?

當我看着它們時,它們都與我一樣!我是否缺少關於XML的東西 - 有沒有有趣的空白空間問題,首都,特殊字符還是讓我的XML只有一個奇怪的gremlin!

它現在正在工作,但我想知道爲什麼。

This Works!

<ScrollView 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:padding="10dip"> 
    <TextView 
     android:id="@+id/about_content" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="@string/about_text" /> 
</ScrollView> 

這不起作用:崩潰:java.lang.runtime.exception。二進制xml文件lin#1:您必須提供layout_width屬性。

<ScrollView 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android.layout_width="fill_parent" 
    android.layout_height="fill_parent" 
    android:padding="10dip"> 
    <TextView 
     android:id="@+id/about_content" 
     android.width ="wrap_content" 
     android.height ="wrap_content" 
     android:text="@string/about_text"/> 
</ScrollView> 
+0

我想你應該留意缺少'layout_width'屬性。另外,您可能希望向我們展示您的XML,以便我們可以幫助您。 – 2011-05-23 20:49:47

+0

@Lukas - 缺少的xml是一個SO格式問題。 – 2011-05-23 20:51:03

+0

android.width是錯誤的。它應該是android:width。這也適用於其他屬性 – Jodes 2011-05-23 20:55:51

回答

5

在XML不會在屬性名的工作,你有時間(.):

​​

android.layout_height 

這就需要使用冒號(: )代替:

android:layout_width 

android:layout_height 
+0

謝謝馬特 - 優秀的東西!疲憊的眼睛! – user763433 2011-05-23 21:16:30

0

以供將來參考的是,你可以用它來幫助你發現所謂的相同文件之間的差異的工具。 Liquid XML Editor就是這樣的一個工具,但還有很多其中包括來自微軟的一款工具,該特性被富有想象力地稱爲xml diff,即xml差異。

相關問題