看老師的word文檔開始學習。復制了一段代碼,在layout中新建了一個Android XML file,發現有提示錯誤。
代碼如下:
<?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:id="@+id/text" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Hello, I am a TextView" /> <Button android:id="@+id/button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Hello, I am a Button" /> </LinearLayout>
錯誤的提示是這樣的:Element type "LinearLayout" must be followed by either attribute specifications, ">" or "/>".
在網上找了很久,都沒有找到我理想的解決方案。這樣幾個小時就過去了。
后來自己無意間試了出來一種辦法,居然可以消除這種錯誤。那就是右鍵點擊這個xml文件,然后new -> Android XML flie -> finish。也就是新建一個相同名字的xml文件來覆蓋這個文件。感覺內容是沒有修改的,但是就是正確了。我的猜測是:word和eclipse的編碼可能不同。但是具體是什么原因就不知道了。