1

Why I'm getting IOException in this peace of code? Thanks.

HttpClient httpclient = new DefaultHttpClient();
HttpGet httpget = new HttpGet("http://www.google.com/");
HttpResponse response;
    try {
        response = httpclient.execute(httpget);
    } catch (ClientProtocolException e) {
         Toast.makeText(this, "ClientProtocolEx", Toast.LENGTH_LONG).show();
         e.printStackTrace();
    } catch (IOException e) {
         Toast.makeText(this, "IOEx", Toast.LENGTH_LONG).show();
         e.printStackTrace();
    } 

Exception:

12-25 18:01:48.992: WARN/System.err(10749): java.net.UnknownHostException: www.google.com
12-25 18:01:48.992: WARN/System.err(10749):     at java.net.InetAddress.lookupHostByName(InetAddress.java:513)
12-25 18:01:48.992: WARN/System.err(10749):     at java.net.InetAddress.getAllByNameImpl(InetAddress.java:278)
12-25 18:01:48.992: WARN/System.err(10749):     at java.net.InetAddress.getAllByName(InetAddress.java:242)
12-25 18:01:48.992: WARN/System.err(10749):     at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:136)
12-25 18:01:48.992: WARN/System.err(10749):     at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
12-25 18:01:48.992: WARN/System.err(10749):     at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
12-25 18:01:48.992: WARN/System.err(10749):     at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:348)
12-25 18:01:48.992: WARN/System.err(10749):     at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
12-25 18:01:48.992: WARN/System.err(10749):     at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
2
  • please add the actual exception to your question. Commented Dec 25, 2010 at 15:51
  • what about giving us the stacktrace and the message of the exception? Commented Dec 25, 2010 at 15:52

1 Answer 1

1
HttpEntity entity = response.getEntity();
String s = entity.toString();

Try adding this after response = httpclient.execute(httpget);

And also if this doesn't help, you must edit your manifest xml file and give your application INTERNET uses permission.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the hint about manifest.xml - that was a root of the problem. As for your first statement - that couldn't possible help because method execution is stopped on the line where it happened and proceed in catch block. Thanks a lot.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.