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

stuck on setListAdapter for Reader App training

Working thru Reader App with video: Adding Data for the List

I get an error with last line with setListAdapter that says: "Multiple Markers at this line

  • adapter cannot be resolved to a type
  • Syntax error on token "adapter", VariableDeclaratorId expected after this token
  • Return type for the method is missing"
import android.os.Bundle;
import android.app.Activity;
import android.app.ListActivity;
import android.view.Menu;
import android.widget.ArrayAdapter;

public class MainListActivity extends ListActivity {

    protected String[] mAndroidNames = {
            "Android beta",
            "Android 1.0",
            "Android 1.1",
            "Froyo",
            "Gingerbread",
            "Jelly Bean",
            "Kit Kat"
    };

    @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);

1 Answer

I feel stupid - too bad I can't just delete this post. I had the last two commands AFTER the closing brace for the method. Corrected code below.

    @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);
    }
Ben Jakuben
Ben Jakuben
Treehouse Teacher

Happens to everyone! Glad you got it working. :)