標籤:
1.錯誤提示:Your content must have a ListView whose id attribute is ‘android.R.id.list‘
對於以上錯誤,其實可能是因為我們要實現對ListView中setOnItemClick的事件監聽而去繼承了LiseActivity,但是卻沒有ListView的標籤,只要在布局檔案中添加定製Layout的代碼,即將ListView的id設定為“@android:id/list”或android:id="@id/android:list",這時可以用getListView來擷取ListView的對象了。
xml代碼如下:
[html] view plaincopy <ListView
android:id="@android:id/list" 或android:id="@id/android:list"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</ListView>
2.同樣容易報此錯誤的還有TabHost,如下:
問題1. 運行Activity的時候出現Your content must have a TabHost whose id attribute is ‘android.R.id.tabhost’
添加Layout的時候,xml跟元素選擇TabHost, 但是ADT沒有添加id屬性, 啟動並執行時候,會提示Your content must have a TabHost
whose id attribute is ‘android.R.id.tabhost’錯誤, 需要添加android:id=”@android:id/tabhost”, 這樣就可以了。
問題2. 運行Activity的時候出現Your TabHost must have a TabWidget whose id attribute is ‘android.R.id.tabcontent’
解決方案: 修改FrameLayout添加id屬性, ADT自動產生的xml檔案中Id是android:id=”@+id/FrameLayout01 ”, 需要修改成下
面的格式android:id=”@android:id/tabcontent ”,這個估計會困擾一大批初學者,誰會想到會修改這個地方,看到錯誤很容易
修改成tabcontent,但是首碼不容易想到。 而且在ADT可視化編輯這個檔案的時候, 介面上顯示NullPointerException,這個是
ADT的一個BUG。
修改後的xml如下:
<?xml version=”1.0″ encoding=”utf-8″?>
<TabHost
android:id=”@android:id/tabhost”
xmlns:android=”http://schemas.android.com/apk/res/android”
android:layout_width=”fill_parent” android:layout_height=”fill_parent”>
<LinearLayout android:id=”@+id/LinearLayout01″ android:layout_height=”fill_parent”
android:layout_width=”fill_parent” android:orientation=”vertical”>
<TabWidget android:id=”@android:id/tabs” android:layout_height=”wrap_content”
android:layout_width=”fill_parent”>
</TabWidget>
<FrameLayout android:id=”@android:id/tabcontent” android:layout_width=”fill_parent”
android:layout_height=”fill_parent”>
</FrameLayout>
</LinearLayout>
</TabHost>
注意: 如果用TabHost的話, 上面標紅的三處必須是一樣, 這個是Google的約定。 而且一個工程中只能有一個TabHost。
來源:http://blog.sina.com.cn/s/blog_5e58565701010bpj.html
解決Your content must have a ListView whose id attribute is 'android.R.id.list'