title: Exception with Internet in Java, Android
body: <p>I try to use internet in my app (Android version 3), I add to manifest necessary permission, but this code doesnt work:</p>
  
  <pre><code>    private void qwer() throws IOException{
  
          DefaultHttpClient d=new DefaultHttpClient();
          HttpGet get=new HttpGet("http://google.com");
          HttpResponse r=d.execute(get);
      }
  </code></pre>
  
  <p>It always throw exception. I use emulator, version Android - 3. </p>
  
  <pre><code>10-07 16:23:27.744: ERROR/AndroidRuntime(3256): Caused by: android.os.NetworkOnMainThreadException
  10-07 16:23:27.744: ERROR/AndroidRuntime(3256):     at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1077)
  10-07 16:23:27.744: ERROR/AndroidRuntime(3256):     at java.net.InetAddress.lookupHostByName(InetAddress.java:481)
  10-07 16:23:27.744: ERROR/AndroidRuntime(3256):     at java.net.InetAddress.getAllByNameImpl(InetAddress.java:281)
  10-07 16:23:27.744: ERROR/AndroidRuntime(3256):     at java.net.InetAddress.getAllByName(InetAddress.java:249)
  10-07 16:23:27.744: ERROR/AndroidRuntime(3256):     at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:136)
  10-07 16:23:27.744: ERROR/AndroidRuntime(3256):     at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
  10-07 16:23:27.744: ERROR/AndroidRuntime(3256):     at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
  10-07 16:23:27.744: ERROR/AndroidRuntime(3256):     at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:359)
  10-07 16:23:27.744: ERROR/AndroidRuntime(3256):     at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
  10-07 16:23:27.744: ERROR/AndroidRuntime(3256):     at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
  10-07 16:23:27.744: ERROR/AndroidRuntime(3256):     at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
  10-07 16:23:27.744: ERROR/AndroidRuntime(3256):     at com.dad.aaa.Qwerty11Activity.qwer(Qwerty11Activity.java:42)
  10-07 16:23:27.744: ERROR/AndroidRuntime(3256):     at com.dad.aaa.Qwerty11Activity.onCreate(Qwerty11Activity.java:31)
  10-07 16:23:27.744: ERROR/AndroidRuntime(3256):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1048)
  10-07 16:23:27.744: ERROR/AndroidRuntime(3256):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1700)
  </code></pre>