android: ListView.setAdapter() is causing IllegalStateException. Not sure how to fix it.
- by Stev0
I'm trying to populate a listview with the contents of various ListAdapters based upon the results of a switch statement nested in an OnItemClickListener. When clicking the item, the application was force closing, so I ran it through the dev tools and android debugger. Eclipse is showing me the in the main thread that the application has suspended due an IllegalStateException.
I have a marginal understanding of what the particular exception indicates, but not sure how to fix it, or what in my code is causing it to be thrown. Code as follows:
final ListView lv = (ListView) findViewById(R.id.main_list);
final String[] autos = getResources().getStringArray(R.array.auto_array);
final ListAdapter la_auto = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_2, autos);
And then further down in the portion dealing with the onclicklistener
gallery.setOnItemClickListener(new OnItemClickListener()
{
public void onItemClick(AdapterView parent, View v, int position, long id)
{
switch(gallery.getSelectedItemPosition())
{
case 0:
lv.setAdapter(la_auto);
break;