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
Lon Sanders
9,931 PointsBuild a Blog Reader Android App Adapting Data for Display in a List Adding Secondary Data with a SimpleAdapter question #2.
Create an ArrayList named 'websites' and add your two HashMap variables to it. Syntax hint: ArrayList<HashMap<String, String>>
I keep getting the same error whatever I try.
"Bummer! Compilation Error! Check your syntax and remember that the ArrayList is declared as 'ArrayList<HashMap<String, String>>' and the constructor looks the same."
I am not sure if this is the correct error code or if the system is stuck. My code is below. Any Ideas?
import java.util.ArrayList;
import java.util.HashMap;
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> webSite1 = new HashMap<String, String>();
HashMap<String, String> webSite2 = new HashMap<String, String>();
webSite1.put(KEY_NAME, "Treehouse");
webSite1.put(KEY_URL, "http://teamtreehouse.com");
webSite2.put(KEY_NAME, "Tyranski");
webSite2.put(KEY_URL, "http://tyranski.com");
ArrayList<HashMap<String, String>> websites = new ArrayList<HashMap<String, String>>();
String name = website.getString(KEY_NAME);
name = Html.fromHtml(name).toString();
String url = website.getString(KEY_URL);
url = Html.fromHtml(url).toString();
}
}
Lon Sanders
9,931 PointsOK, I tried that and still get the exact same error message. Are there any other error messages available that would lead me to the error of my ways?
I keep getting: "Bummer! Compilation Error! Check your syntax and remember that the ArrayList is declared as 'ArrayList<HashMap<String, String>>' and the constructor looks the same."
And why is the flow of the code not more like the flow we went over in class like this?
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_website_list);
ArrayList<HashMap<String, String>> websites =
new ArrayList<HashMap<String, String>>(); {
String name = website.getString(KEY_NAME);
name = Html.fromHtml(name).toString();
String url = website.getString(KEY_URL);
url = Html.fromHtml(url).toString();
HashMap<String, String> webSite1 = new HashMap<String, String>();
HashMap<String, String> webSite2 = new HashMap<String, String>();
webSite1.put(KEY_NAME, "ABC");
webSite1.put(KEY_URL, "http://abc.com");
webSite2.put(KEY_NAME, "CBS");
webSite2.put(KEY_URL, "http://cbs.com");
websites.add(webSite1);
websites.add(webSite2);
}
String[] keys = { KEY_NAME, KEY_URL };
int[] ids = { android.R.id.text1, android.R.id.text2 };
}
}
Sanat Tripathi
8,109 PointsThe following is my code for second question , which perfectly passes the test, take a look...
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> hash1 = new HashMap<String, String> ();
HashMap<String, String> hash2 = new HashMap<String, String> ();
hash1.put(KEY_NAME , "someName");
hash1.put(KEY_URL , "www.someName.com");
hash2.put(KEY_NAME , "someOtherName");
hash2.put(KEY_URL , "www.someOtherName.com");
ArrayList<HashMap<String, String>> websites = new ArrayList<HashMap<String, String>> ();
websites.add(hash1);
websites.add(hash2);
}
}
Sanat Tripathi
8,109 Points@Lon : why do you have that curly brace after your ArrayList declaration ??
Lon Sanders
9,931 PointsSanatkumar,
Thank you for helping pull my head out of my butt. I guess I was getting ahead of myself again.
Thanks again.
Sanat Tripathi
8,109 PointsNo problem, however if you don't mind please select my answer as the best answer I will gain some points :)
Ben Jakuben
Treehouse TeacherThese types of errors are easier to see in a real IDE like Eclipse or Android Studio! Hopefully we can enhance our code challenge engine with that type of feedback down the road.
1 Answer
John Paul Ashenfelter
1,118 PointsGlad this was solved successfully. Way to go everyone!
Sanat Tripathi
8,109 PointsSanat Tripathi
8,109 PointsYou didn't add the hashMap variables inside the ArrayList. For adding use the "add" method of ArrayList.
For e.g.
websites.add(webSite1);
websites.add(webSite2);