2011-10-15 22 views
1

我有一個列表活動,使用的佈局不僅僅是列表視圖。它也有一個按鈕和一個微調。我收到錯誤,說我需要一個名爲'list'的listview小部件。如何爲我的ListActivity定義列表?

10-15 23:28:36.131:ERROR/AndroidRuntime(448):java.lang.RuntimeException:無法啓動活動ComponentInfo {rams.rss/rams.rss.RamsRSS}:java.lang.RuntimeException:Your內容必須有一個ListView,其id屬性是'android.R.id.list'

但是,它已經有一個名爲list的listview對象。我用一個解決方案在這裏:

Why does my Android app keep telling me I need to define a ListView id when it is already defined?

它不僅造成在其中添加了.OUT後綴複製另一個錯誤。

rams_layout.xml - > rams_layout.out.xml

這裏是XML文件的內容,我使用:

<?xml version="1.0" encoding="utf-8"?> 
    <RelativeLayout 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:orientation="vertical" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 
     <Button android:text="Back" android:layout_width="wrap_content"   android:id="@+id/button1" android:layout_height="wrap_content"   android:layout_alignParentTop="true" android:layout_alignParentLeft="true"></Button> 
     <Spinner android:id="@+id/spinner1"   android:layout_width="wrap_content"   android:layout_height="wrap_content"   android:layout_alignParentTop="true" android:layout_toRightOf="@+id/button1"   android:layout_alignParentRight="true"></Spinner> 
     <ListView android:id="@android:id/list" android:layout_width="match_parent"   android:layout_height="wrap_content"   android:layout_below="@+id/spinner1" android:layout_alignParentLeft="true"   android:layout_alignParentBottom="true"></ListView> 

    </RelativeLayout> 

關於如何解決此問題的任何想法?

+1

可以發佈後在您活動的onCreate方法的代碼? – goto10

+0

可以解釋你確切的錯誤嗎? –

回答

0

嘗試清理您的項目。在Eclipse中,這是來自主菜單的Project | Clean。從命令行,這是ant clean

它只引起另一個錯誤,其中添加了帶有.out後綴的副本。 rams_layout.xml - > rams_layout.out.xml

很可能是因爲您試圖在編輯器中將XML文件作爲活動選項卡來運行Android項目。我認爲這個問題已得到解決 - 確保您使用的是Eclipse的ADT插件的最新版本。

0

我注意到了一件事 - 你的ListView的ID被格式化爲一種有趣的方式。嘗試改變其Android:id來:

<ListView android:id="@+id/list" ... 

我有相同的設置的活動,這是我引用我的ListView:

ListView list = (ListView) findViewById(R.id.list); 
list.setAdapter(... 
相關問題