-1

When I use normal Java socket programming in Android, the app crashes.

Socket sock=new Socket(Ip,Port);
DataInputStream din=new DataInputStream(sock.getInputStream());
  • Possible duplicate of [Java socket programming - Wont work in Android 4.1?](http://stackoverflow.com/questions/12380850/java-socket-programming-wont-work-in-android-4-1) – DarkDust Apr 03 '16 at 11:04
  • All the networking task should be out of main thread ,it will work if work other than main ui thread – Alok Apr 03 '16 at 11:09
  • Use LogCat to examine the Java stack trace associated with your crash: https://stackoverflow.com/questions/23353173/unfortunately-myapp-has-stopped-how-can-i-solve-this – CommonsWare Apr 03 '16 at 12:13

1 Answers1

0

I think you cannot run network operations in UI Thread, so start another Thread, or use AsyncTask, or anything else. Another reason could be permissions, add these lines in your manifest <uses-permission android:name="android.permission.INTERNET"/>

thekekc
  • 206
  • 2
  • 12