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
Jasper van Riet
737 PointsCode 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);
}
}
}
Nathan MacDonald
2,889 PointsAgree, 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
Treehouse TeacherHi 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.
Allan Evans
9,501 PointsThanks for pointing that out Jasper, got stuck on there myself.
Allan Evans
9,501 PointsOh got it, if you follow the instructions it says "CodeChallenge" and for any string you put " " .
Rajesh Mule
2,125 PointsLog.e("CodeChallenge", "randomString", e);
Juan Gallardo
1,568 PointsThe 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";
}
Jasper van Riet
737 PointsJasper van Riet
737 PointsNever 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.