开发者

Why does my XML code crash when its identical to other XML code that runs fine?

I'm building my first Android program from a book. It kept crashing on开发者_如何学Python an XML file. I downloaded the xml code from the book, used it and it ran fine!

When I look at them, they both look the same to me! Am I missing something about XML - are there funny empty space problems, capitals, special characters or has my XML just got an odd gremlin in it!

It's working now, but I'd like to know why.

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>

This doesn't work: crashes with: java.lang.runtime.exception. Binary xml file lin #1: You must supply layout_width attribute.

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


In the XML that does not work, you've got periods (.) in the attribute names:

android.layout_width

and

android.layout_height

which need to use colons (:) instead:

android:layout_width

and

android:layout_height


for future reference their are tools that you can use to help you spot differences between supposedly identical files. Liquid XML Editor is one such tool but there are many more including one from Microsoft, the feature is imaginatively called xml diff ie xml difference.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜