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 trialDalton Coble
6,489 PointsI can not use setListAdapter in my code please help
I have tried to use it but just get an error please help.
5 Answers
David Axelrod
36,073 PointsI had the same error. make sure the code is within the onCreate method. There should be two curly braces after setListAdapter
diego zarate
18,143 Pointsi 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 ?
Slava Fleer
6,086 Pointswhich 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)
diego zarate
18,143 Pointshi 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
Ivan Knyazev
4,927 PointsYou are out of the scope, do it in onCreate method)))
Dave Idell
5,664 Pointsdo 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;
Dalton Coble
6,489 PointsI have updated them but that line of code still has an error
Ivan Knyazev
4,927 PointsYour class must extends ListActivity. Please check your class
Dave Idell
5,664 Pointsdoes your DayAdapter declaration extend BaseAdapter?
public class DayAdapter extends BaseAdapter
Slava Fleer
6,086 Pointswright the error, please