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 trialdlpuxdzztg
8,243 PointsError when setting adapter
Hello,
I am having trouble running this app. Every time I press the '7 DAY' button, I get a pop-up saying "Unfortunately, Stormy has stopped.". The error was:
java.lang.IllegalStateException: ArrayAdapter requires the resource ID to be a TextView
I still couldn't figure out what the problem was, here is my code:
package com.diego.stormy.ui;
import android.app.ListActivity;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import com.diego.stormy.R;
public class DailyForecastActivity extends ListActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_daily_forecast);
String[] daysOfTheWeek = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" };
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.activity_list_item,
daysOfTheWeek);
setListAdapter(adapter);
}
}
Please help!
3 Answers
Kourosh Raeen
23,733 PointsHi Diego - Change:
android.R.layout.activity_list_item
to:
android.R.layout.simple_list_item_1
Paul Stevens
4,125 PointsHello, I notice that the second parameter you pass when constructing the array adapter is different to that in the video. You are passing:
android.R.layout.activity_list_item
Try passing:
android.R.layout.simple_list_item_1
:)
dlpuxdzztg
8,243 PointsThanks alot guys :)