My Client Class is under with my log traces but my app. eventually stops with the error "client has stopped",I have created datagram socket with datagram packet to send on the receiving app. and I have specified the IP of the receiving device. Please Identify where is my error,Thanks in advance.
public class MainActivity extends Activity {
private DatagramSocket socket;
String str;
private static final int SERVERPORT = 6000;
private static final String SERVER_IP = "192.168.1.101";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
new Thread(new ClientThread()).start();
}
public void onClick(View view) {
try {
EditText et = (EditText) findViewById(R.id.EditText01);
str = et.getText().toString();
} catch (Exception e) {
e.printStackTrace();
}
}
class ClientThread implements Runnable {
@Override
public void run() {
try {
socket = new DatagramSocket(SERVERPORT);
InetAddress serverAddr = InetAddress.getByName(SERVER_IP);
DatagramPacket packet = new DatagramPacket(str.getBytes(), str.length(),serverAddr,SERVERPORT);
socket.send(packet);
} catch (UnknownHostException e1) {
e1.printStackTrace();
} catch (IOException e1) {
e1.printStackTrace();
}
}
}}
My log cat is :
08-25 16:27:22.657: W/dalvikvm(555): threadid=11: thread exiting with uncaught exception (group=0x409961f8)
08-25 16:27:22.677: E/AndroidRuntime(555): FATAL EXCEPTION: Thread-75
08-25 16:27:22.677: E/AndroidRuntime(555): java.lang.NullPointerException
08-25 16:27:22.677: E/AndroidRuntime(555): at com.example.client.MainActivity$ClientThread.run(MainActivity.java:51)
08-25 16:27:22.677: E/AndroidRuntime(555): at java.lang.Thread.run(Thread.java:856)
08-25 16:28:04.288: I/Process(555): Sending signal. PID: 555 SIG: 9