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

Adding Secondary Data with a SimpleAdapter Code Challenge

I guess I'm a little confused on what question one is asking. I have this as my code:

    HashMap<String, String> varOne = new HashMap<String, String>();
    varOne.put(KEY_NAME, value);
    varOne.put(KEY_URL, value);

    HashMap<String, String> varTwo = new HashMap<String, String>();
    varTwo.put(KEY_NAME, value);
    varTwo.put(KEY_URL, value);

I get the error:

Compilation Error! Make sure you use String as both type parameters for the HashMap variables, i.e. <String, String>. Don't forget them in the constructors, too!

I have <String, String> as the parameters for the HashMap, but I cannot pass on or even get another error.

Do I need both varOne and varTwo, or is it looking for something like the "blogPosts" & "blogPost" HashMaps from the video?

Do I need to create the ArrayList<HashMap<String, String>> then populate the ArrayList with firstHashMapVar.add(otherHashMapVar)?

Do I need to define the values in the .put method with a .getString(KEY_X)? (The X being NAME or URL)

4 Answers

Ben Jakuben
STAFF
Ben Jakuben
Treehouse Teacher

That code is all correct, but how is the value variable being set? That probably has something to do with the problem.

I guess that is where I am confused. Am I to assume there is a resource like a JSON array that has these values and use a for loop like in the tutorial? To say:

    String name = getString(KEY_NAME);
    String url = getString(KEY_URL);

then change "value" in the HashMap's put method to the strings: name and url respectively doesn't return much of anything when it's not looking anywhere for a value. Do I need to define something like:

for (int i = 0; i < jsonWebsites.length(); i++) {
    JSONObject website = jsonWebsites.getJSONObject(i);
    String name = website.getString(KEY_NAME);
            ...
    }

?

Ben Jakuben
STAFF
Ben Jakuben
Treehouse Teacher

I guess the instructions are not perfectly clear. I will make a note to update those. You can make the name and value for each website whatever you want. They just need to be String values, like this:

varOne.put(KEY_NAME, "Treehouse");

DERP. I'm always making things more complicated than they really are. Thanks for your help!