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 trialremi poolen
6,697 Pointserror: exception IOException is never thrown in body of corresponding try statement
i followed along with the video, making a weather app. but on the onResponse method of a CallBack i get the above error.
Code:
Call call = client.newCall(request);
call.enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
}
@Override
public void onResponse(Call call, Response response) throws IOException {
Log.v(TAG, response.body().string());
try {
if (response.isSuccessful()) {
}
else {
alertUserAboutError();
}
} catch (IOException e) {
Log.e(TAG, "IO Exception caught", e);
}
}
});
1 Answer
Martin Klestil
5,520 PointsIt's a small bug, he can not write a log because the tag only exists locally in the if block. Copy Log.v (TAG, response.body (). String ()); in front of the if block.
I hope this helps you.
@Override
public void onResponse(Call call, Response response) throws IOException {
try {
Log.v(TAG, response.body().string());
if (response.isSuccessful()) {
}
else{
alertUserAboutError();
}
} catch (IOException e) {
Log.e(TAG, "IO Exception caught: ", e);
}
}