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

Moving Work from the Main Thread to an AsyncTask

Hi Ben,

My code does't shows http response code 200. Here is my log cat. help me fix this.

12-28 14:33:34.953: D/libc-netbsd(24297): getaddrinfo: blog.teamtreehouse.com NO result from proxy 
12-28 14:33:34.954: W/Trace(24297): Unexpected value from nativeGetEnabledTags: 0
12-28 14:33:34.957: W/Trace(24297): Unexpected value from nativeGetEnabledTags: 0
12-28 14:33:34.958: W/Trace(24297): Unexpected value from nativeGetEnabledTags: 0
12-28 14:33:34.960: I/System.out(24297): [CDS][DNS]Unable to resolve host "blog.teamtreehouse.com": No address associated with hostname
12-28 14:33:34.960: E/MainListActivity(24297): Exception caught:

2 Answers

Ben Jakuben
STAFF
Ben Jakuben
Treehouse Teacher

Can you paste in your code? Are you including the "http://" part of the URL?

I Ben,

I have the same problem, here is my code:

private class GetBlogPostTask extends AsyncTask<Object,Void,String>{

        @Override
        protected String doInBackground(Object... arg0) {
            int responseCode=-1;
            try {
                URL blogFeedUrl = new URL("http://blog.teamtreehouse.com/api/get_recent_summary/?count=" + NUMBER_OF_POSTS);
                HttpURLConnection connection= (HttpURLConnection)blogFeedUrl.openConnection();
                connection.connect();

                responseCode=connection.getResponseCode();
                Log.i(TAG, "Code: "+responseCode);
            }
            catch(MalformedURLException e){
                Log.e(TAG, "Exception caught: ", e);
            }
            catch (IOException e) {
                Log.e(TAG, "Exception caught: ", e);
            }
            catch (Exception e){
                Log.e(TAG, "Exception caught: ", e);
            }
            return "Code: "+responseCode;
        }
    }
Ben Jakuben
Ben Jakuben
Treehouse Teacher

Can you paste in the logcat details of your exception?