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
Rafael Moreno
17,642 PointsAdapting Data for Display in a List
Here's the challenge: Inside the ‘onCreate()’ method, create two HashMap<String, String> variables and in each one, store a website name value using KEY_NAME as the key and the website URL value using KEY_URL as the key.
and here's the error: Bummer! Make sure you add the name of the website using the KEY_NAME variable for both HashMap variables.
When I use the KEY_NAME for both HashMaps then I get a compilation error. Help would be appreciated.
import android.os.Bundle;
import android.widget.SimpleAdapter;
public class WebsiteListActivity extends ListActivity {
public static final String KEY_NAME = "name";
public static final String KEY_URL = "url";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_website_list);
String[] keys = { KEY_NAME, KEY_URL };
int[] ids = { android.R.id.text1, android.R.id.text2 };
// Add code here!
HashMap<String, String> KEY_NAME = new HashMap <String, String>();
HashMap<String, String> KEY_URL = new HashMap <String, String>();
//key.Put(KEY_NAME, value);
//id.Put(KEY_URL);
}
}
2 Answers
Philip Larson
7,553 PointsAt first, the challenge text is a little bit hard to understand, but when you are done it makes more sense :) I feel the challenge text could be improved with something like "Inside the ‘onCreate()’ method, create two HashMap<String, String> variables with any variable name."
So, first of all, you shouldn't name your HashMaps KEY_NAME and KEY_URL. They can be called whatever you want. Second, you want to put in a name in each of them using KEY_NAME as key, and then assign a url using the key KEY_URL. So you want to do something like
map.put(KEY_NAME, "treehouse");
Where map is one of your HashMaps. You should do this on both names and urls on both HashMap objects :)
Hope this helps!
Rafael Moreno
17,642 PointsI know it's late, but super helpful. Thanks!