RuntimeException: Your content must have a ListView when id attribute is 'android.R.id.list' What should I do?

Asked 2 years ago, Updated 2 years ago, 24 views

There was a runtime error with the following message, but I don't know what I did wrong.

java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
@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);
}

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

What did I do wrong?

android

2022-09-21 17:33

1 Answers

<ListView android:id="@android:id/list"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"/>

In the list view, give android:id as @android:id/list like that. You have to do that when you use the list activity.


2022-09-21 17:33

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.