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

Blog Reader project - Opening a Webpage in the Browser - Code Challenge 2/2

I've been stuck on this challenge for a while. I think the hint might be throwing me off. Please help.

@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
  super.onListItemClick(l, v, position, id);
  String url = mUrls.getString();
  Intent intent = new Intent(Intent.ACTION_VIEW);
  intent.setData(Uri.parse(url));
  startActivity(intent);
}

4 Answers

Ok, so basically what is happening is, when you click an item in the list, you want to go to a URL corresponding to that list in your browser. You are given that mUrls is an array (hint hint) of string values. What you're attempting to do is to set the data of the intent to a string version of an array, Not a single URL string. This: String url = mUrls.getString(); needs to be something along the lines of: String url = mUrls[position]; So you are fetching the string value from the array at the correct position! Hope this doesn't confuse you more :S

Hi there,

I am also having the same issues. Here is the code I wrote:

   @Override
protected void onListItemClick(ListView l, View v, int position, long id) {
    // Add code here!
    super.onListItemClick(l, v, position, id);
    String url = mUrls[0];
    Intent intent = new Intent(Intent ACTION_VIEW);
    intent.setData(Uri.parse(url));
    startActivity(intent);
}

But it's obviously not correct. Any ideas?

... Sorry for the spam, I wrote Intent ACTION_VIEW instead of Intent.ACTION_VIEW. It's now working. Thanks for the tip Liam

Thanks, Liam. That helped. On to the next lesson...