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 trialNoah Schill
10,020 PointsDefine Hashmap?
It is telling me to define these HashMaps using KEY_NAME as the key and to use KEY_URL as the value. It is saying I did it wrong. Did I?
import android.os.Bundle;
import android.widget.SimpleAdapter;
public class WebsiteListActivity extends ListActivity {
public static final String KEY_NAME = "myName";
public static final String KEY_URL = "myUrl";
@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> site1 = new HashMap<String, String>();
HashMap<String, String> site2 = new HashMap<String, String>();
site1.put(KEY_NAME, KEY_URL);
site2.put(KEY_NAME, KEY_URL);
}
}
1 Answer
Dan Johnson
40,533 PointsIt's expecting both keys to be paired with values that you provide for both HashMaps. Since this is to represent a website, it'll look something like this:
site1.put(KEY_NAME, "example");
site1.put(KEY_URL, "example.com");
Noah Schill
10,020 PointsNoah Schill
10,020 Pointsimport android.os.Bundle; import android.widget.SimpleAdapter;
public class WebsiteListActivity extends ListActivity {
}
I tried that but I get an error saying: Make sure you add the name of the website using the KEY_NAME variable for both HashMap variables.
;/
Dan Johnson
40,533 PointsDan Johnson
40,533 PointsYou need to define the key value pairs for site2 as well.
Noah Schill
10,020 PointsNoah Schill
10,020 PointsOh! I understand now. Thank you!