Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android Build a Blog Reader Android App Rebuilding from Scratch Adding Data for the List

Furkan Demirkan
Furkan Demirkan
7,926 Points

setListAdapter shows up as an error! Help!!

I did everything the same as in the video but an error appeared : cannot resolve method 'setListAdapter(android.widget.ArrayAdapter) Please help!!

code:

import android.app.Activity; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.widget.ArrayAdapter; import android.widget.ListAdapter;

import java.lang.reflect.Array;

public class MainListActivity extends Activity {

protected String[] mAndroidNames = {

        "Android Beta",
        "Android 1.1",
        "Cupcake",
        "Donut",
        "Eclair",
        "Froyo",
        "Gingerbread",
        "Honeycomb",
        "Jellybean",
};

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main_list);

    ArrayAdapter adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, mAndroidNames);
    setListAdapter(adapter);
}

ps: Also, import android.widget.ListAdapter; and import java.lang.reflect.Array; shows up as "unused import statment"

1 Answer

Hi Furkan,

The error is
```public class MainListActivity extends Activity {}

change it to  

```public class MainListActivity extends ListActivity {}

Basically extend ListActivity instead of Activity in general.

Edit: the unused imports are not much of an issue. It just means that you aren't using them at the moment. You can delete them if you want.

Furkan Demirkan
Furkan Demirkan
7,926 Points

Thanks, must have missed that part :) Much Appreciated

You are welcome. I added additional info, for the imports question you had too.