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

Lee Marshall
Lee Marshall
1,763 Points

stuck at Trying Code and Catching Exceptions > Challenge task 2 of 3

Android Development > Build a Blog Reader Android App > Getting Data from the Web > Trying Code and Catching Exceptions > Challenge task 2 of 3

Question: Inside onCreate(), declare a URL variable named treehouseUrl and initialize it with the URL constructor, using the URL variable as the parameter. Put this line inside a try block and then catch a MalformedURLException named e. Don't do anything in the catch block yet.

Error message: Bummer! Don't forget to initialize "treehouseUrl" with the "URL(String url)" constructor.

Why won't it let me continue?

My code:

        // Add Task 2 code here
      try {
        URL treehouseUrl = new URL(URL);
      } catch (MalformedURLException e){
      }

4 Answers

Joe Brown
Joe Brown
21,465 Points

Did you get this sorted out? I just ran it again for you and it worked fine for me. Assuming you have your code inside of the onCreate method you should be good. The code challenge engine could have just been giving you problems at that moment, that's happened to me before

Lee Marshall
Lee Marshall
1,763 Points

After about 20 minutes I just decided to manually skip it, got to the next quiz and it had the output and took it in that format and went back and it worked. Something with my format it didn't like.

Thanks.

Erich Hoffer
Erich Hoffer
3,453 Points

It would not work for me so I had to skip it. Same code as OP used. Retyped it up and even went back to the video then moved forward to the quiz. Still same issue.

Erich Hoffer
Erich Hoffer
3,453 Points

I went back and got it to work. It was a curly brace in my instance.