Asked  7 Months ago    Answers:  2   Viewed   37 times

I have created an xml file like this:

<?xml version="1.0" encoding="utf-8"?>
<ListView xmlns:android=""
    android:id="@+id/list" >

and an activity:

public class ExampleActivity extends ListActivity {
    /** Called when the activity is first created. */
    public void onCreate(Bundle savedInstanceState) {   

As you see, I have not done anything else. But I'am getting the error:

Your content must have a ListView whose id attribute is ''

Even though I have the android:id="@+id/list" line in my xml.

What is the problem?



Rename the id of your ListView like this,

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

Since you are using ListActivity your xml file must specify the keyword android while mentioning to a ID.

If you need a custom ListView then instead of Extending a ListActivity, you have to simply extend an Activity and should have the same id without the keyword android.

Tuesday, June 1, 2021
answered 7 Months ago

Your problem is you are trying to extends ListActivity and you don't have a ListView with


You need to have a ListView in your xml with that id. Please add it to your xml

You can tell by the following line in your logcat

Caused by: java.lang.RuntimeException: Your content must have a ListView whose id attribute is ''

If you find the next line that references your Activity it will tell you the class and line number


So MainActivityNext line 28 is showing the exception.


As stated in a comment, please don't just post unformatted logcat when asking for help. Please try to look for where the error is occurring and post relevant code along with a description of what the problem is. This one was easy to see from the error but usually we will need to see some code

You can use CTRL+K to format your code and logcat or use the coding brackets above {}

Friday, August 6, 2021
answered 4 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :