Socket Creation causing force close
<p>whenever I open a socket in android, the program immediately force closes. Here's the code:</p>

<pre><code>package com.bensherman.acc;

import java.io.IOException;
import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);



            try {
                Socket socket = new Socket("192.168.43.253", 4452);
            } catch (UnknownHostException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }


    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

}
</code></pre>

<p>Here's my manifest:</p>

<pre><code>  &lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.bensherman.acc"
    android:versionCode="1"
    android:versionName="1.0" &gt;

    &lt;uses-sdk
        android:minSdkVersion="9"
        android:targetSdkVersion="14" /&gt;
    &lt;uses-permission android:name="android.permission.INTERNET"/&gt;
    &lt;uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/&gt;
    &lt;uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/&gt;

    &lt;application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" &gt;
        &lt;activity
            android:name="com.bensherman.acc.MainActivity"
            android:label="@string/app_name" &gt;
            &lt;intent-filter&gt;
                &lt;action android:name="android.intent.action.MAIN" /&gt;

                &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
            &lt;/intent-filter&gt;
        &lt;/activity&gt;
    &lt;/application&gt;

&lt;/manifest&gt;
</code></pre>

<p>Here's the log:</p>

<pre><code>    05-20 19:26:59.539: E/Trace(26558): error opening trace file: No such file or directory (2)
05-20 19:26:59.649: D/AndroidRuntime(26558): Shutting down VM
05-20 19:26:59.649: W/dalvikvm(26558): threadid=1: thread exiting with uncaught exception (group=0x2b545300)
05-20 19:26:59.669: E/AndroidRuntime(26558): FATAL EXCEPTION: main
05-20 19:26:59.669: E/AndroidRuntime(26558): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.bensherman.acc/com.bensherman.acc.MainActivity}: android.os.NetworkOnMainThreadException
05-20 19:26:59.669: E/AndroidRuntime(26558):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2190)
05-20 19:26:59.669: E/AndroidRuntime(26558):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2215)
05-20 19:26:59.669: E/AndroidRuntime(26558):    at android.app.ActivityThread.access$600(ActivityThread.java:145)
05-20 19:26:59.669: E/AndroidRuntime(26558):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1211)
05-20 19:26:59.669: E/AndroidRuntime(26558):    at android.os.Handler.dispatchMessage(Handler.java:99)
05-20 19:26:59.669: E/AndroidRuntime(26558):    at android.os.Looper.loop(Looper.java:137)
05-20 19:26:59.669: E/AndroidRuntime(26558):    at android.app.ActivityThread.main(ActivityThread.java:4978)
05-20 19:26:59.669: E/AndroidRuntime(26558):    at java.lang.reflect.Method.invokeNative(Native Method)
05-20 19:26:59.669: E/AndroidRuntime(26558):    at java.lang.reflect.Method.invoke(Method.java:511)
05-20 19:26:59.669: E/AndroidRuntime(26558):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
05-20 19:26:59.669: E/AndroidRuntime(26558):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:558)
05-20 19:26:59.669: E/AndroidRuntime(26558):    at dalvik.system.NativeStart.main(Native Method)
05-20 19:26:59.669: E/AndroidRuntime(26558): Caused by: android.os.NetworkOnMainThreadException
05-20 19:26:59.669: E/AndroidRuntime(26558):    at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1117)
05-20 19:26:59.669: E/AndroidRuntime(26558):    at libcore.io.BlockGuardOs.connect(BlockGuardOs.java:84)
05-20 19:26:59.669: E/AndroidRuntime(26558):    at libcore.io.IoBridge.connectErrno(IoBridge.java:127)
05-20 19:26:59.669: E/AndroidRuntime(26558):    at libcore.io.IoBridge.connect(IoBridge.java:112)
05-20 19:26:59.669: E/AndroidRuntime(26558):    at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:192)
05-20 19:26:59.669: E/AndroidRuntime(26558):    at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
05-20 19:26:59.669: E/AndroidRuntime(26558):    at java.net.Socket.startupSocket(Socket.java:566)
05-20 19:26:59.669: E/AndroidRuntime(26558):    at java.net.Socket.tryAllAddresses(Socket.java:127)
05-20 19:26:59.669: E/AndroidRuntime(26558):    at java.net.Socket.&lt;init&gt;(Socket.java:177)
05-20 19:26:59.669: E/AndroidRuntime(26558):    at java.net.Socket.&lt;init&gt;(Socket.java:149)
05-20 19:26:59.669: E/AndroidRuntime(26558):    at com.bensherman.acc.MainActivity.onCreate(MainActivity.java:22)
05-20 19:26:59.669: E/AndroidRuntime(26558):    at android.app.Activity.performCreate(Activity.java:5008)
05-20 19:26:59.669: E/AndroidRuntime(26558):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
05-20 19:26:59.669: E/AndroidRuntime(26558):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
05-20 19:26:59.669: E/AndroidRuntime(26558):    ... 11 more
</code></pre>

<p>Does anyone have an idea what's the problem? It isn't a problem if I say Socket socket = new Socket(). I have a server running on my computer, although both the laptop and development device are connected via a phone running wifi tether. </p>
