Eugene
Eugene

Reputation: 60184

IO Exception on invoking execute() method of HttpGet class

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)

Upvotes: 1

Views: 2312

Answers (1)

evilone
evilone

Reputation: 22740

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.

Upvotes: 1

Related Questions