fatal exception in android
<p>i have written simple client server socket programming code as follow</p>

<p>MyServer.java</p>

<pre><code> import java.io.DataInputStream;
 import java.io.DataOutputStream;
 import java.io.IOException;
 import java.net.ServerSocket;
 import java.net.Socket;


 public class MyServer {

   public static void main(String[] args){
   ServerSocket serverSocket = null;
   Socket socket = null;
   DataInputStream dataInputStream = null;
   DataOutputStream dataOutputStream = null;

    try {
         serverSocket = new ServerSocket(8888);
         System.out.println("Listening :8888");
        } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
   }

   while(true){
    try {
    socket = serverSocket.accept();
    dataInputStream = new DataInputStream(socket.getInputStream());
    dataOutputStream = new DataOutputStream(socket.getOutputStream());
    System.out.println("ip: " + socket.getInetAddress());
    System.out.println("message: " + dataInputStream.readUTF());
    dataOutputStream.writeUTF("Hello!");
    } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
   }
   finally{
   if( socket!= null){
 try {
  socket.close();
 } catch (IOException e) {
  // TODO Auto-generated catch block
  e.printStackTrace();
 }
}

if( dataInputStream!= null){
 try {
  dataInputStream.close();
 } catch (IOException e) {
  // TODO Auto-generated catch block
  e.printStackTrace();
 }
}

if( dataOutputStream!= null){
 try {
  dataOutputStream.close();
 } catch (IOException e) {
  // TODO Auto-generated catch block
  e.printStackTrace();
    }
   }
  }
 }
 }}
</code></pre>

<p>android client is as follows</p>

<p>MyClientActivity.java</p>

<pre><code>package com.exercise.AndroidClient;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.Socket;
import java.net.UnknownHostException;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.os.Bundle;

public class MyClientActivity extends Activity {
EditText textOut;
TextView textIn;

 /** Called when the activity is first created. */
 @Override
 public void onCreate(Bundle savedInstanceState) {
     super.onCreate(savedInstanceState);
     setContentView(R.layout.main);

     textOut = (EditText)findViewById(R.id.textout);
     Button buttonSend = (Button)findViewById(R.id.send);
     textIn = (TextView)findViewById(R.id.textin);
     buttonSend.setOnClickListener(buttonSendOnClickListener);
 }

 Button.OnClickListener buttonSendOnClickListener
 = new Button.OnClickListener(){

@Override
public void onClick(View arg0) {
 // TODO Auto-generated method stub
 Socket socket = null;
 DataOutputStream dataOutputStream = null;
 DataInputStream dataInputStream = null;

 try {
  socket = new Socket("113.193.42.220", 8888);
  dataOutputStream = new DataOutputStream(socket.getOutputStream());
  dataInputStream = new DataInputStream(socket.getInputStream());
  dataOutputStream.writeUTF(textOut.getText().toString());
  textIn.setText(dataInputStream.readUTF());
 } catch (UnknownHostException e) {
  // TODO Auto-generated catch block
  e.printStackTrace();
 } catch (IOException e) {
  // TODO Auto-generated catch block
  e.printStackTrace();
 }
 finally{
  if (socket != null){
   try {
    socket.close();
   } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
   }
  }

  if (dataOutputStream != null){
   try {
    dataOutputStream.close();
   } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
   }
  }

  if (dataInputStream != null){
   try {
    dataInputStream.close();
   } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
   }
  }
 }
}};
 }
</code></pre>

<p>Main.xml</p>

<pre><code> &lt;?xml version="1.0" encoding="utf-8"?&gt;
 &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:orientation="vertical"
 android:layout_width="fill_parent"
 android:layout_height="fill_parent"
 &gt;
 &lt;TextView
 android:layout_width="fill_parent"
 android:layout_height="wrap_content"
 android:text="@string/hello"
 /&gt;
 &lt;EditText
 android:id="@+id/textout"
 android:layout_width="fill_parent"
 android:layout_height="wrap_content"
 /&gt;
 &lt;Button
 android:id="@+id/send"
 android:layout_width="fill_parent"
 android:layout_height="wrap_content"
 android:text="Send"
 /&gt;
 &lt;TextView
 android:id="@+id/textin"
 android:layout_width="fill_parent"
 android:layout_height="wrap_content"
 /&gt;
 &lt;/LinearLayout&gt;
</code></pre>

<p>AndroidManifest.xml</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.exercise.AndroidClient"
android:versionCode="1"
android:versionName="1.0" &gt;
&lt;uses-permission android:name="android.permission.INTERNET"/&gt;

&lt;uses-sdk android:minSdkVersion="15" /&gt;

&lt;application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name" &gt;
    &lt;activity
        android:name=".MyClientActivity"
        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>I am getting FatalException on execution of client.pls suggest me how to handle this.
i have tried my pc's ip address and 127.0.0.1 also so do i have any problem with ip address or anything else is causing FatalException pls help me out.</p>

<p>logcat is as follow</p>

<pre><code>02-21 21:05:48.793: D/gralloc_goldfish(553): Emulator without GPU emulation detected.
02-21 21:08:39.794: D/AndroidRuntime(553): Shutting down VM
02-21 21:08:39.794: W/dalvikvm(553): threadid=1: thread exiting with uncaught exception (group=0x409c01f8)
02-21 21:08:39.824: E/AndroidRuntime(553): FATAL EXCEPTION: main
02-21 21:08:39.824: E/AndroidRuntime(553): android.os.NetworkOnMainThreadException
02-21 21:08:39.824: E/AndroidRuntime(553):  at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1099)
02-21 21:08:39.824: E/AndroidRuntime(553):  at libcore.io.BlockGuardOs.connect(BlockGuardOs.java:84)
02-21 21:08:39.824: E/AndroidRuntime(553):  at libcore.io.IoBridge.connectErrno(IoBridge.java:127)
02-21 21:08:39.824: E/AndroidRuntime(553):  at libcore.io.IoBridge.connect(IoBridge.java:112)
02-21 21:08:39.824: E/AndroidRuntime(553):  at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:192)
02-21 21:08:39.824: E/AndroidRuntime(553):  at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
02-21 21:08:39.824: E/AndroidRuntime(553):  at java.net.Socket.startupSocket(Socket.java:566)
02-21 21:08:39.824: E/AndroidRuntime(553):  at java.net.Socket.tryAllAddresses(Socket.java:127)
02-21 21:08:39.824: E/AndroidRuntime(553):  at java.net.Socket.&lt;init&gt;(Socket.java:177)
02-21 21:08:39.824: E/AndroidRuntime(553):  at java.net.Socket.&lt;init&gt;(Socket.java:149)
02-21 21:08:39.824: E/AndroidRuntime(553):  at com.exercise.AndroidClient.MyClientActivity$1.onClick(MyClientActivity.java:44)
02-21 21:08:39.824: E/AndroidRuntime(553):  at android.view.View.performClick(View.java:3511)
02-21 21:08:39.824: E/AndroidRuntime(553):  at android.view.View$PerformClick.run(View.java:14105)
02-21 21:08:39.824: E/AndroidRuntime(553):  at android.os.Handler.handleCallback(Handler.java:605)
02-21 21:08:39.824: E/AndroidRuntime(553):  at android.os.Handler.dispatchMessage(Handler.java:92)
02-21 21:08:39.824: E/AndroidRuntime(553):  at android.os.Looper.loop(Looper.java:137)
02-21 21:08:39.824: E/AndroidRuntime(553):  at android.app.ActivityThread.main(ActivityThread.java:4424)
02-21 21:08:39.824: E/AndroidRuntime(553):  at java.lang.reflect.Method.invokeNative(Native Method)
02-21 21:08:39.824: E/AndroidRuntime(553):  at java.lang.reflect.Method.invoke(Method.java:511)
02-21 21:08:39.824: E/AndroidRuntime(553):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
02-21 21:08:39.824: E/AndroidRuntime(553):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
02-21 21:08:39.824: E/AndroidRuntime(553):  at dalvik.system.NativeStart.main(Native Method)
</code></pre>
