android: ListView.setAdapter() is causing IllegalStateException. Not sure how to fix it.

Posted by Stev0 on Stack Overflow See other posts from Stack Overflow or by Stev0
Published on 2011-03-13T08:06:46Z Indexed on 2011/03/13 8:10 UTC
Read the original article Hit count: 193

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;

© Stack Overflow or respective owner

Related posts about android

Related posts about listadapter