-1

I'm getting this weird error:

05-01 14:04:42.589: E/AndroidRuntime(3261): Caused by: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'

I have seen a quite a number of posts but none of them worked for me. I am just trying to populate an array in to a ListView. It was working all fine, but I wanted to use some SharedPreferences in my code so I extended PreferenceActivity class. I guess since then this error started to be thrown.

RivieraKid
  • 5,923
  • 4
  • 38
  • 47
rosesr
  • 749
  • 1
  • 7
  • 10

1 Answers1

2

The exception is pretty clear, if you extend ListActivity(PreferenceActivity extends ListActivity so has the same behaviour) and use a custom content view(with setContentView()), then in that layout file you must have a ListView element with the id:

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

so the ListActivity knows on which ListView to bind the data.

user
  • 86,916
  • 18
  • 197
  • 190
  • Hey thanks Luksprog what do you mean byt a custom content view? can you give me an example please? – rosesr May 01 '12 at 13:49
  • @rosesr I guess your using something like `setContentView(R.layout.a_layout_file)` in your activity. You should use the default `PreferenceActivity` and simply load your preferences(without setting the content view) file with the `addPreferencesFromResource` method. – user May 01 '12 at 13:53
  • I dont really get what you are saying here. what do you mean by "simply load your preferences(without setting the content view) file with the addPreferencesFromResource method" – rosesr May 01 '12 at 15:10
  • @rosesr Check as an example this tutorial( http://www.kaloer.com/android-preferences ) and see how that method is used. – user May 01 '12 at 16:17