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 a Default Adapter

I can not use setListAdapter in my code please help

I have tried to use it but just get an error please help.

5 Answers

I had the same error. make sure the code is within the onCreate method. There should be two curly braces after setListAdapter

i have the same error here is my code:

public class DailyForecastActivity extends ListActivity {

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


    String[] daysOfTheWeek = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" };
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
            android.R.layout.simple_list_item_1,
            daysOfTheWeek);
    setListAdapter(adapter);
}

and the message error is: Error:(23, 5) invalid method declaration; return type required Error:(23, 27) <identifier> expected

does anyone know how to fix this ?

which line is 23 and what wrote after expected. and check that your activity_dayly_forecast name also with y in daYly, but it is not the problem i believe. also did you add special id to the list? (@android:id/list)

hi thanks a lot for your answer, the problem was that i was writing my code outside of the onCreate method, i just put it inside and works fine

You are out of the scope, do it in onCreate method)))

do you have all of the imports required at the top?

import android.app.ListActivity; import android.os.Bundle; import android.widget.ArrayAdapter; import com.teamtreehouse.stormy.R;

I have updated them but that line of code still has an error

Your class must extends ListActivity. Please check your class

does your DayAdapter declaration extend BaseAdapter?

public class DayAdapter extends BaseAdapter

wright the error, please