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 Android Lists and Adapters (2015) Standard ListViews Using an ArrayAdapter

what did i do wrong here

im getting a lot of errors

AppListActivity.java
import android.app.ListActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;

public class AppListActivity extends ListActivity {

    public String[] mApps = {
        "Instagram",
        "Pinterest",
        "Pocket",
        "Twitter"
    };
String[] mApps = {"Instagram","Pinterest","Pocket","Twitter" };
  ArrayAdapter<String>adopter=new ArrayAdopter<String>(this android.R.layout.simple_list_item_1, mApps); setListAdpter(adopter);

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_app_list);
    }
}

2 Answers

Kourosh Raeen
Kourosh Raeen
23,733 Points

You're defining mApps twice. Remove the line:

String[] mApps = {"Instagram","Pinterest","Pocket","Twitter" };

Move the line defining the adapter into onCreate and after setContentView. Also watch out for spelling errors. It's ArrayAdapter not ArrayAdopter. Your'e also missing a comma after this:

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

Finally, don't forget to set the adapter:

setListAdapter(Adapter);

still getting errors, whats wrong with this?

import android.app.ListActivity; import android.os.Bundle; import android.view.View; import android.widget.ArrayAdapter;

public class AppListActivity extends ListActivity {

public String[] mApps = {
    "Instagram",
    "Pinterest",
    "Pocket",
    "Twitter"
};


@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_app_list);
    ArrayAdapter<String>adapter=new ArrayAdopter<String>(this android.R.layout.simple_list_item_1, mApps); setListAdpter(adopter);

setListAdapter(Adapter);

}

}

Kourosh Raeen
Kourosh Raeen
23,733 Points

Hi Tommy - As I said in the above post, you have a spelling error. It's ArrayAdapter not ArrayAdopter. Also, you still haven't added a comma after this.