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

sven molhuijsen
sven molhuijsen
7,091 Points

problem while applying ArrayAdapter

I'm following along with the treehouse course for a blog reader app, but when i try to apply the arrayadapter it gives me the error connot resolve problems at setListAadapter

My code:

''' public class mainListActivity extends ActionBarActivity {

protected String[] mAndroidNames= {
        "android beta",
        "android 1.0",
        "android 1.1",
        "cupcake",
        "donut",
        "Eclair",
        "Froyo",
        "Gingerbread",
        "Honeycomb",
        "Ice cream sandwich",
        "jellybean",
        "KITKAT",
        "Lion?"
};
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main_list);


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


@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main_list, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();
    if (id == R.id.action_settings) {
        return true;
    }
    return super.onOptionsItemSelected(item);
}

}

'''

i hope you can help me

2 Answers

Hi Sven,

The rest of the code looks fine just that I spotted an error here

setListAdapter adapter;  

setListAdapter is a method that takes an adapter as parameter. But what seems here is that you are declaring a setListAdapter variable called adapter which is incorrect

Change the above to

setListAdapter(adapter);

Try this . Hope it works. Ask again if you have issues.

sven molhuijsen
sven molhuijsen
7,091 Points

thnx for your help, but unfortunatly it does not workt, now it gives the error ''' "cannot resolve method android.widget.Arrayadapter<java.lang.String>" '''

sven molhuijsen
sven molhuijsen
7,091 Points

found the error, i used the wrong class, i used actionbaractivity instead of listactivity. thanks for the help