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 Using Intents to Display and Share Posts Opening a Webpage in the Browser

Justin Stevens
Justin Stevens
5,850 Points

Code Challenge trouble

I'm having some serious trouble with the 2 part of Code Challenge for Using Intents to Display and Share...

The stipulation for the second part of this code challenge is this:

The member variable 'mUrls' is filled with a few URLs. In the 'onListItemClick()' method, declare and start an Intent that causes the URL tapped on to be viewed in the browser. Hint: The String URL needs to be set as the data for the Intent as a Uri object.

Here is the supplied code:

import android.os.Bundle; import android.widget.ArrayAdapter; import android.view.View; import android.view.ListView; import android.content.Intent; import android.net.Uri;

public class CustomListActivity extends ListActivity {

protected String[] mUrls = { "http://www.teamtreehouse.com", "http://developer.android.com", "http://www.github.com" };

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_custom_list);

    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, mUrls);
    setListAdapter(adapter);
}

@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
    // Add code here!
}

}

Here's what I've added in the onListItemClick method:

@Override protected void onListItemClick(ListView l, View v, int position, long id) { // Add code here! super.onListItemClick(l, v, position, id);

  String aUrl;
  Uri challenge = intent.getData();
  Intent intent = new Intent(aUrl);

  intent.setData(Uri.parse(mUrls));
}

}

Here are the error codes I get with this one:

./CustomListActivity.java:27: cannot find symbol symbol : variable intent location: class CustomListActivity Uri challenge = intent.getData(); ^ ./CustomListActivity.java:30: parse(java.lang.String) in android.net.Uri cannot be applied to (java.lang.String[]) intent.setData(Uri.parse(mUrls)); ^ 2 errors

Where am I going wrong? Can someone give me a big hint, because I am lost? BTW, this is just the latest iteration of this attempt. There are many others.

2 Answers

Laurel Smith
Laurel Smith
18,836 Points

I'm having trouble with this to. Do you remember what the solution was?

Justin Stevens
Justin Stevens
5,850 Points

Yes. I kinda cheated and looked ahead. The solution is actually pretty simple, and sorry for the late response.