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 Build a Blog Reader Android App Adapting Data for Display in a List Adding Secondary Data with a SimpleAdapter

J Smillie
J Smillie
39,714 Points

I keep getting error messages saying that there are unexpected characters where I'm supposed to put in the values in...

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 };

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

  HashMap<String, String> site2 = new HashMap<String, String>();
    site2.put(KEY_NAME, );
    site2.put(KEY_URL, );
}

}

Can anyone tell me why?

J Smillie
J Smillie
39,714 Points

I have tried various text values... I haven't just been leaving it blank as the above code suggests. I've just done that here so you can see what I mean.

This is the task:

Inside the onCreate() method, create two HashMap<String, String> variables named site1 and site2. Then for each one, put a website name value using KEY_NAME as the key, and then put a URL value using KEY_URL as the key. The name and URL values can be whatever you choose.

3 Answers

Paolo Scamardella
Paolo Scamardella
24,828 Points

site1.put(KEY_NAME, ); site1.put(KEY_URL, );

site2.put(KEY_NAME, ); site2.put(KEY_URL, );

Your hashmaps needs to have a key-value pair, and you only have keys and no values. Also, you cannot leave in any method a comma without passing in another parameter following it.

You can do as Paolo Scamardella did. In his answer, he did not provide any string values for each hash map, unfortunately.

As described in the Code Challenge text, "The name and URL values can be whatever you choose".

      // Add code here!
      HashMap<String, String> site1 = new HashMap<String, String>();
      HashMap<String, String> site2 = new HashMap<String, String>();

      site1.put(KEY_NAME, "a" );
      site1.put(KEY_URL, "aa" );

      site2.put(KEY_NAME, "b" );
      site2.put(KEY_URL, "bb" );

I hope my answer cleared up the missing information from Paolo Scamardella's answer.

Provide an example of the values you set in the hashmaps? The current empty values are invalid.

I just provided an answer to your question, in order to clear up things a little ;-)