Bummer! You must be logged in to access this page.

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

Code Challenge: Trying Code and Catching Exceptions

Third task: Log the exception using the Log.e() method that takes an exception variable as its 3rd parameter. Use the String "CodeChallenge" for the 1st parameter and any String for the 2nd parameter.

I have no idea what I'm doing wrong here.

This is my code:

package com.example;

import android.os.Bundle;
import android.view.View;
import java.net.MalformedURLException;
import android.util.Log;

public class MainListActivity extends ListActivity {

public static final String URL = "teamtreehouse.com";
public static final String CodeChallenge = MainListActivity.class.getSimpleName();  

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main_list);
  try{
    URL treehouseUrl = new URL(URL);
  }
  catch(MalformedURLException e){
    Log.e(CodeChallenge, randomString, e);
  }


}

}

Never mind, the next code challenge had the answer.

Log.e("CodeChallenge", "MalformedURLException caught!", e);

It might be helpful to say in the description for the third task that CodeChallenge needs the quotes around it.

Agree, had all my code right except for those quotes. Glad I wasn't the only one or I might have been stuck on that one a while.

5 Answers

Nick Pettit
STAFF
Nick Pettit
Treehouse Teacher

Hi Jasper van Riet,

Glad you were able to figure it out! Sorry for the confusion. I'll pass this feedback along to Ben Jakuben, our Android teacher.

Thanks for pointing that out Jasper, got stuck on there myself.

Oh got it, if you follow the instructions it says "CodeChallenge" and for any string you put " " .

Rajesh Mule
Rajesh Mule
2,125 Points

Log.e("CodeChallenge", "randomString", e);

The answer is

Log.e("CodeChallenge", "MalformedURLException caught!", e);

And it fits into the rest of the code like this

package com.example;

import android.os.Bundle;
import android.view.View;
import java.net.MalformedURLException;
import android.util.Log;



public class MainListActivity extends ListActivity {

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

        // Add Task 2 code here
        try {
            URL treehouseUrl = new URL(URL);
        } 
        catch(MalformedURLException e) {
            Log.e("CodeChallenge", "MalformedURLException caught!", e);
        }

    }
  public static final String URL ="teamtreehouse.com";
}