So I’m having a problem making a new socket. I had this program that worked perfectly on gingerbread, but since my HTC sensation xe updated to ICS the program crashes each time I try to open a socket. I had a program sending gyro data to a server on my local network. Since this problem came up I’ve reduced my code down to the smallest component that still causes the problem, so here it is.
package com.mytesting;
import java.net.Socket;
import android.app.Activity;
import android.os.Bundle;
import java.io.*;
import java.net.*;
public class SocketTestingActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
try {
Socket clientSocket = new Socket("192.168.1.7", 23000);
} catch (UnknownHostException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
}
I’ve included:
<uses-permission android:name="android.permission.INTERNET" />
in the manifest file too.
All of this stuff was working just perfectly before ICS. Now when I run the program, I just get the message “Unfortunately, SocketTesting has stopped.”
Does anyone know what I am doing wrong, I am quite new to android programming, and java programming in general.
Thanks for any help, guys.
In ICS you can not perform network operations on the UI thread. Move it to separate thread or use AsyncTask.