RuntimeException: your content must have a ListView whose id attribute is 'android.R.id.list'

I get a runtime exception

java.lang.RuntimeException: your content must have a ListView whose attribute id is "android.R.id.list"

I do not know what is wrong.

@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.newslist); mDbHelper.open(); fillData(); } private void fillData() { Bundle extras = getIntent().getExtras(); long catID = extras.getLong("cat_id"); Cursor c = mDbHelper.fetchNews(catID); startManagingCursor(c); String[] from = new String[] { DBHelper.KEY_TITLE }; int[] to = new int[] { R.id.newslist_text }; SimpleCursorAdapter notes = new SimpleCursorAdapter(this, R.layout.text_newslist, c, from, to); setListAdapter(notes); } 

newslist.xml

 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content"> <ListView android:id="@+id/catnewslist" android:layout_width="wrap_content" android:layout_height="wrap_content"> </ListView> </LinearLayout> 

text_newslist.xml

 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content"> <TextView android:text="@+id/newslist_text" android:id="@+id/newslist_text" android:layout_width="wrap_content" android:layout_height="wrap_content"> </TextView> </LinearLayout> 
+84
android
Jun 14 '10 at 19:45
source share
7 answers
 <ListView android:id="@android:id/list" android:layout_width="fill_parent" android:layout_height="fill_parent"/> 

This will solve the error if you still want to use ListActivity.

+183
Mar 28 '11 at 13:52
source share

Delete the call to setContentView - you don't need it in ListActivity unless you are doing something radical. The code should work without it.

+51
Jun 14 '10 at 19:54
source share

Another way: do not ListActivity . Just extends the Activity , then you can create your list in the form of setContentView() and get a list view of findViewById(R.id.yourlistview) .

If you exit ListActivity , then do not use setContentView() . You need to get the default list view hosted in the list activity on getListView() .

+26
Jul 02 2018-12-12T00:
source share

I had a similar problem with the error message you received, and I found that this is due to the fact that I am expanding ListActivity, and not just Activity (what I get for reassigning code from another project;))

+10
Mar 26 2018-11-11T00:
source share
 <ListView android:id="@id/android:list" android:layout_width="fill_parent" android:layout_height="wrap_content" android:drawSelectorOnTop="false" android:scrollbars="vertical"/> 
+5
May 21 '13 at 2:16
source share

I look like that too. In my case (maybe not relevant to your case, just pass it on to others) in the mainActivity.java class yourClassName extends ListActivity(){...} change to yourClassName extends Activity(){...}

+2
01 Oct '15 at 9:32
source share

I also ran into this problem, I expanded my activity class from listactivity, but the identifier of my list was not defualt, I changed it to a list and now it works fine. Asim soroya

+1
Dec 31 '11 at 9:54
source share



All Articles