Click here to Skip to main content
15,878,814 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i write TCP Serve App but its not working right.
i see /000.000.000.000:4444 i think its not get ip adress.

i got this:

12-15 08:09:25.020 854-854/com.example.onur.testasync I/System.out﹕ Server started. Listening to the port 4444
12-15 08:09:25.020 854-854/com.example.onur.testasync D/AndroidRuntime﹕ Shutting down VM
12-15 08:09:25.050 854-854/com.example.onur.testasync W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0xb4af3ba8)
12-15 08:09:25.080 854-854/com.example.onur.testasync E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.example.onur.testasync, PID: 854
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.onur.testasync/com.example.onur.testasync.MyActivity}: android.os.NetworkOnMainThreadException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
at android.app.ActivityThread.access$800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.os.NetworkOnMainThreadException
at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1145)
at libcore.io.BlockGuardOs.accept(BlockGuardOs.java:54)
at java.net.PlainSocketImpl.accept(PlainSocketImpl.java:98)
at java.net.ServerSocket.implAccept(ServerSocket.java:203)
at java.net.ServerSocket.accept(ServerSocket.java:128)
at com.example.onur.testasync.MyActivity.Call(MyActivity.java:67)
at com.example.onur.testasync.MyActivity.onCreate(MyActivity.java:35)
at android.app.Activity.performCreate(Activity.java:5231)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
            at android.app.ActivityThread.access$800(ActivityThread.java:135)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:136)
            at android.app.ActivityThread.main(ActivityThread.java:5017)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
            at dalvik.system.NativeStart.main(Native Method)
12-15 08:09:37.090 960-960/com.example.onur.testasync I/System.out﹕ Server started. Listening to the port 4444
12-15 08:09:37.090 960-960/com.example.onur.testasync D/AndroidRuntime﹕ Shutting down VM
12-15 08:09:37.090 960-960/com.example.onur.testasync W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0xb4af3ba8)
12-15 08:09:37.130 960-960/com.example.onur.testasync E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.example.onur.testasync, PID: 960
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.onur.testasync/com.example.onur.testasync.MyActivity}: android.os.NetworkOnMainThreadException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
at android.app.ActivityThread.access$800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.os.NetworkOnMainThreadException
at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1145)
at libcore.io.BlockGuardOs.accept(BlockGuardOs.java:54)
at java.net.PlainSocketImpl.accept(PlainSocketImpl.java:98)
at java.net.ServerSocket.implAccept(ServerSocket.java:203)
at java.net.ServerSocket.accept(ServerSocket.java:128)
at com.example.onur.testasync.MyActivity.Call(MyActivity.java:67)
at com.example.onur.testasync.MyActivity.onCreate(MyActivity.java:35)
at android.app.Activity.performCreate(Activity.java:5231)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
            at android.app.ActivityThread.access$800(ActivityThread.java:135)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:136)
            at android.app.ActivityThread.main(ActivityThread.java:5017)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
            at dalvik.system.NativeStart.main(Native Method)
12-15 08:09:43.350 960-960/com.example.onur.testasync I/Process﹕ Sending signal. PID: 960 SIG: 9
12-15 08:16:46.143 1160-1173/com.example.onur.testasync I/System.out﹕ Server started. Listening to the port 4444
12-15 08:16:46.353 1160-1160/com.example.onur.testasync D/gralloc_goldfish﹕ Emulator without GPU emulation detected.
12-15 08:20:34.363 1202-1215/com.example.onur.testasync I/System.out﹕ Server started. Listening to the port 4444
12-15 08:20:34.593 1202-1202/com.example.onur.testasync D/gralloc_goldfish﹕ Emulator without GPU emulation detected.
12-15 08:21:26.123 1244-1257/com.example.onur.testasync I/System.out﹕ Server started. Listening to the port 4444
12-15 08:21:26.403 1244-1244/com.example.onur.testasync D/gralloc_goldfish﹕ Emulator without GPU emulation detected.
Posted
Comments
Fredrik Bornander 16-Dec-14 2:23am    
Are you doing network operations on the main thread?
android.os.NetworkOnMainThreadException seems to indicate that and you can't do that. Do all your network calls on a separate thread.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900