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 trialJ Smillie
39,714 PointsI 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?
3 Answers
Paolo Scamardella
24,828 Pointssite1.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.
poltexious
Courses Plus Student 6,993 PointsYou 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.
miguelcastro2
Courses Plus Student 6,573 PointsProvide an example of the values you set in the hashmaps? The current empty values are invalid.
poltexious
Courses Plus Student 6,993 PointsI just provided an answer to your question, in order to clear up things a little ;-)
J Smillie
39,714 PointsJ Smillie
39,714 PointsI 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.