0

I am currently attempting to fix the error "Your content must have a ListView whose id attribute is 'android.R.list'.

I have found the answer from the following question on Stack Exchange:

Your content must have a ListView whose id attribute is 'android.R.id.list'

I had applied the solution, but then I wished to ask the question:

"Then how do I reference the android-defined XML tag?

However due to the reputation system, I was unable to comment this small question. I apologise for this, but can someone please answer this question?

Thank you in advance.

For your information, this is my listview:

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

And this is what I am trying to pass:

   lv = (ListView) convertView.findViewById(R.id.ExceedingList);

And this is the error I'm getting:

 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.denny.phonebelt/com.example.denny.phonebelt.SettingsMenu}: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'

Just in case the problem is caused by another bug for some reason, I'll CP the actual code here:

    final Button ExceedingLimitButton = (Button)findViewById(R.id.ExceedingLimitButton);
    ExceedingLimitButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            final AlertDialog.Builder ExceedingLimitDialog = new AlertDialog.Builder(SettingsMenu.this);
            //Setting ListView
            LayoutInflater inflater = getLayoutInflater();
            View convertView = inflater.inflate(R.layout.exceeding_dialog, null);
            lv = (ListView) convertView.findViewById(android.R.id.list);
            ArrayAdapter<String> adapter = new ArrayAdapter<>(SettingsMenu.this, android.R.layout.simple_list_item_single_choice, ExceedingSelection);
            lv.setAdapter(adapter);
            lv.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
                @Override
                public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                    int SelectedItem = Integer.parseInt(ExceedingSelection[position]);
                    PhoneBelt.setExceedInt(SelectedItem);
                    String Selection = getString(R.string.Selection);
                    String message = (Selection + SelectedItem);
                    Toast toast = Toast.makeText(SettingsMenu.this, message, Toast.LENGTH_LONG);
                    toast.show();
                }

                @Override
                public void onNothingSelected(AdapterView<?> parent) {
                    Toast toast = Toast.makeText(SettingsMenu.this, "You have not selected anything", Toast.LENGTH_SHORT);
                    toast.show();
                }
            });
            ExceedingLimitDialog.setView(convertView);
            ExceedingLimitDialog.setTitle(R.string.Exceeding_Limit_Title);
            ExceedingLimitDialog.setMessage(R.string.Exceeding_Limit_Message);
            ExceedingLimitDialog.setCancelable(true);
            AlertDialog alert = ExceedingLimitDialog.create();
            alert.show();
        }
    });
Community
  • 1
  • 1
Mildwood
  • 349
  • 2
  • 13

3 Answers3

2

Instead of:

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

write:

 android:id="@+id/list"

You have to declare a new ID and mark the list with it.

Jokab
  • 2,939
  • 1
  • 15
  • 26
R. Zagórski
  • 20,020
  • 5
  • 65
  • 90
  • Change the id you are looking for in `Activity` to `R.id.list` – R. Zagórski Jul 06 '16 at 12:08
  • Huh, still not working. I also tried android.R.id.list – Mildwood Jul 06 '16 at 12:14
  • And the error? Can't be the same, as with those fixes you are not using the `android.R.id.list` – R. Zagórski Jul 06 '16 at 12:15
  • Yeah, still the same. It must be something to do with another ID I haven't seen? – Mildwood Jul 06 '16 at 12:17
  • After looking at your code, I see the problem in `public void onClick(View v)` method. You have written `lv = (ListView) convertView.findViewById(android.R.id.list);` and that means you haven't changed the id you are looking for. – R. Zagórski Jul 06 '16 at 12:19
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/116570/discussion-between-minusreputation-and-r-zagorski). – Mildwood Jul 06 '16 at 12:20
0

Use this :

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">
    <ListView
        android:id="@id/list"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
    </ListView>
</LinearLayout>
Svel04
  • 149
  • 10
0

Your reference of java code is ExceedingList . but in xml is list. and also you should create the new id.

so ,

 android:id="@+id/ExceedingList"

if you use android:id="@android:id/ExceedingList" means you are trying to refer already created id (ExceedingList)

and then call,

ListView lv = (ListView) convertView.findViewById(R.id.ExceedingList);

This may helps you

Sathish Kumar J
  • 4,280
  • 1
  • 20
  • 48