I'm trying to create an android client app that connects to a server on my desktop.
I successfully telneted to the server from my laptop.
I have put INTERNET and NETWORK permissions in manifest file.
The program crashes when creating the socket and eclipse debuuger gets me to socket.class source file.
UPDATE: here's my complete code
public class EsmFamilActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_esm_famil);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.esm_famil, menu);
return true;
}
//handler for sendtoserver
public void sendToServer(View view){
...
String host = "192.168.1.7";
int port = 8888;
try{
Socket s = new Socket(host, port);
Writer out = new OutputStreamWriter(s.getOutputStream());
out.write(data + "\n");
out.flush();
s.close();
}catch (UnknownHostException ex) {
ex.printStackTrace();
}catch(IOException ex){
ex.printStackTrace();
}
}
}
and here is my logcat
01-18 21:43:06.908: D/TextView(1608): Constructor -- Got mEditTextBackgroundColor
01-18 21:43:09.658: W/IInputConnectionWrapper(1608): beginBatchEdit on inactive InputConnection
01-18 21:43:09.668: W/IInputConnectionWrapper(1608): endBatchEdit on inactive InputConnection
01-18 21:43:11.448: W/IInputConnectionWrapper(1608): beginBatchEdit on inactive InputConnection
01-18 21:43:11.448: W/IInputConnectionWrapper(1608): endBatchEdit on inactive InputConnection
01-18 21:43:46.018: D/AndroidRuntime(1608): Shutting down VM
01-18 21:43:46.018: W/dalvikvm(1608): threadid=1: thread exiting with uncaught exception (group=0x42f02500)
01-18 21:43:46.038: E/AndroidRuntime(1608): FATAL EXCEPTION: main
01-18 21:43:46.038: E/AndroidRuntime(1608): java.lang.IllegalStateException: Could not execute method of the activity
01-18 21:43:46.038: E/AndroidRuntime(1608): at android.view.View$1.onClick(View.java:3678)
01-18 21:43:46.038: E/AndroidRuntime(1608): at android.view.View.performClick(View.java:4300)
01-18 21:43:46.038: E/AndroidRuntime(1608): at android.view.View$PerformClick.run(View.java:18026)
01-18 21:43:46.038: E/AndroidRuntime(1608): at android.os.Handler.handleCallback(Handler.java:730)
01-18 21:43:46.038: E/AndroidRuntime(1608): at android.os.Handler.dispatchMessage(Handler.java:92)
01-18 21:43:46.038: E/AndroidRuntime(1608): at android.os.Looper.loop(Looper.java:150)
01-18 21:43:46.038: E/AndroidRuntime(1608): at android.app.ActivityThread.main(ActivityThread.java:5162)
01-18 21:43:46.038: E/AndroidRuntime(1608): at java.lang.reflect.Method.invokeNative(Native Method)
01-18 21:43:46.038: E/AndroidRuntime(1608): at java.lang.reflect.Method.invoke(Method.java:525)
01-18 21:43:46.038: E/AndroidRuntime(1608): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
01-18 21:43:46.038: E/AndroidRuntime(1608): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
01-18 21:43:46.038: E/AndroidRuntime(1608): at dalvik.system.NativeStart.main(Native Method)
01-18 21:43:46.038: E/AndroidRuntime(1608): Caused by: java.lang.reflect.InvocationTargetException
01-18 21:43:46.038: E/AndroidRuntime(1608): at java.lang.reflect.Method.invokeNative(Native Method)
01-18 21:43:46.038: E/AndroidRuntime(1608): at java.lang.reflect.Method.invoke(Method.java:525)
01-18 21:43:46.038: E/AndroidRuntime(1608): at android.view.View$1.onClick(View.java:3673)
01-18 21:43:46.038: E/AndroidRuntime(1608): ... 11 more
01-18 21:43:46.038: E/AndroidRuntime(1608): Caused by: android.os.NetworkOnMainThreadException
01-18 21:43:46.038: E/AndroidRuntime(1608): at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1133)
01-18 21:43:46.038: E/AndroidRuntime(1608): at libcore.io.BlockGuardOs.connect(BlockGuardOs.java:84)
01-18 21:43:46.038: E/AndroidRuntime(1608): at libcore.io.IoBridge.connectErrno(IoBridge.java:127)
01-18 21:43:46.038: E/AndroidRuntime(1608): at libcore.io.IoBridge.connect(IoBridge.java:112)
01-18 21:43:46.038: E/AndroidRuntime(1608): at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:192)
01-18 21:43:46.038: E/AndroidRuntime(1608): at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
01-18 21:43:46.038: E/AndroidRuntime(1608): at java.net.Socket.startupSocket(Socket.java:566)
01-18 21:43:46.038: E/AndroidRuntime(1608): at java.net.Socket.tryAllAddresses(Socket.java:127)
01-18 21:43:46.038: E/AndroidRuntime(1608): at java.net.Socket.<init>(Socket.java:177)
01-18 21:43:46.038: E/AndroidRuntime(1608): at java.net.Socket.<init>(Socket.java:149)
01-18 21:43:46.038: E/AndroidRuntime(1608): at com.example.myfirstapp.EsmFamilActivity.sendToServer(EsmFamilActivity.java:61)
01-18 21:43:46.038: E/AndroidRuntime(1608): ... 14 more
01-18 21:43:53.518: I/Process(1608): Sending signal. PID: 1608 SIG: 9
01-18 21:43:53.668: D/TextView(2467): Constructor - Got Res id for appearance for textColorPrimaryInverse
01-18 21:43:53.668: W/ResourceType(2467): Skipping entry 0x1060085 in package table 0 because it is not complex!
01-18 21:43:53.668: D/TextView(2467): Constructor - Got appearance for textColorPrimaryInverse
01-18 21:43:53.668: D/TextView(2467): Constructor -- Got mEditTextBackgroundColor
01-18 21:43:53.998: D/libEGL(2467): loaded /vendor/lib/egl/libEGL_POWERVR_SGX544_115.so
01-18 21:43:54.078: D/libEGL(2467): loaded /vendor/lib/egl/libGLESv1_CM_POWERVR_SGX544_115.so
01-18 21:43:54.088: D/libEGL(2467): loaded /vendor/lib/egl/libGLESv2_POWERVR_SGX544_115.so
01-18 21:43:54.088: E/IMGSRV(2467): :0: PVRDRMOpen: TP3, ret = 42
01-18 21:43:54.098: E/IMGSRV(2467): :0: PVRDRMOpen: TP3, ret = 45
01-18 21:43:54.098: E/IMGSRV(2467): :0: PVRDRMOpen: TP3, ret = 46
01-18 21:43:54.098: E/IMGSRV(2467): :0: PVRDRMOpen: TP3, ret = 46
01-18 21:43:54.098: E/IMGSRV(2467): :0: PVRDRMOpen: TP3, ret = 46
01-18 21:43:54.108: E/IMGSRV(2467): :0: PVRDRMOpen: TP3, ret = 48
01-18 21:43:54.138: D/OpenGLRenderer(2467): Enabling debug mode 0