我正在將一臺機器上的一個仿真器實例的消息傳輸到同一臺機器上的另一個仿真器實例。 (我猜) 客戶端運行正常。但是,當我點擊一個按鈕,從客戶端數據傳輸到服務器我得到了(SCOKET,的getOutputStream())客戶端服務器應用程序在android NullPointer錯誤?
PrintWriter out = new PrintWriter(new BufferedWriter(
new OutputStreamWriter(socket.getOutputStream())),
true);
空指針異常我有時也得到了許可,不得以客戶吃了飯錯誤
我有完成所有重定向,並且在Android清單文件中也加入INTERNET標籤,
我得到的服務器權限被拒絕錯誤而崩潰,但我加上網後允許標籤服務器工作.. 但是,當我加了相同的標記,以客戶清單文件客戶端崩潰
SO我不能夠通過添加INTERNET標籤 同時刪除權限被拒絕的錯誤是不能夠清除空指針異常
而且在客戶端和本地機器有不同的時區。 默認情況下,android模擬器不會使用本地TZ。
所以我設置了-timezone選項,甚至不會改變timzone區域 AFAIK我想我正在做的事情正確w.r.t端口和ips。 創建套接字時沒有錯誤,但只有在使用socket.ouputstream時纔有錯誤? 有沒有防火牆問題。 ?
我已經廣泛搜索並且不確定問題是什麼。 期待您的幫助。 謝謝。
編輯:
我使用的客戶端服務器代碼從這裏NickT Connecting 2 Emulator instances In Android 和已經修改了一點 我得到的誤差3 ,當我打印錯誤:
11-25 18:59:06.185: W/System.err(388): java.net.SocketException: Permission denied
11-25 18:59:06.185: W/System.err(388): at org.apache.harmony.luni.platform.OSNetworkSystem.socket(Native Method)
11-25 18:59:06.185: W/System.err(388): at dalvik.system.BlockGuard$WrappedNetworkSystem.socket(BlockGuard.java:347)
11-25 18:59:06.185: W/System.err(388): at org.apache.harmony.luni.net.PlainSocketImpl.create(PlainSocketImpl.java:220)
11-25 18:59:06.185: W/System.err(388): at java.net.Socket.startupSocket(Socket.java:618)
11-25 18:59:06.185: W/System.err(388): at java.net.Socket.<init>(Socket.java:258)
11-25 18:59:06.185: W/System.err(388): at net.wipp.ece.ClAct.onCreate(ClAct.java:40)
11-25 18:59:06.185: W/System.err(388): at android.app.Activity.performCreate(Activity.java:4397)
11-25 18:59:06.185: W/System.err(388): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1048)
11-25 18:59:06.185: W/System.err(388): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1779)
11-25 18:59:06.185: W/System.err(388): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1831)
11-25 18:59:06.185: W/System.err(388): at android.app.ActivityThread.access$500(ActivityThread.java:122)
11-25 18:59:06.185: W/System.err(388): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1024)
11-25 18:59:06.185: W/System.err(388): at android.os.Handler.dispatchMessage(Handler.java:99)
11-25 18:59:06.185: W/System.err(388): at android.os.Looper.loop(Looper.java:132)
11-25 18:59:06.185: W/System.err(388): at android.app.ActivityThread.main(ActivityThread.java:4123)
11-25 18:59:06.185: W/System.err(388): at java.lang.reflect.Method.invokeNative(Native Method)
11-25 18:59:06.185: W/System.err(388): at java.lang.reflect.Method.invoke(Method.java:491)
11-25 18:59:06.185: W/System.err(388): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
11-25 18:59:06.185: W/System.err(388): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
11-25 18:59:06.185: W/System.err(388): at dalvik.system.NativeStart.main(Native Method)
11-25 19:00:14.045: W/System.err(388): java.lang.NullPointerException
11-25 19:00:14.055: W/System.err(388): at net.wipp.ece.ClAct$1.onClick(ClAct.java:54)
11-25 19:00:14.055: W/System.err(388): at android.view.View.performClick(View.java:3110)
11-25 19:00:14.065: W/System.err(388): at android.view.View$PerformClick.run(View.java:11934)
11-25 19:00:14.065: W/System.err(388): at android.os.Handler.handleCallback(Handler.java:587)
11-25 19:00:14.065: W/System.err(388): at android.os.Handler.dispatchMessage(Handler.java:92)
11-25 19:00:14.065: W/System.err(388): at android.os.Looper.loop(Looper.java:132)
11-25 19:00:14.065: W/System.err(388): at android.app.ActivityThread.main(ActivityThread.java:4123)
11-25 19:00:14.065: W/System.err(388): at java.lang.reflect.Method.invokeNative(Native Method)
11-25 19:00:14.065: W/System.err(388): at java.lang.reflect.Method.invoke(Method.java:491)
11-25 19:00:14.065: W/System.err(388): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
11-25 19:00:14.065: W/System.err(388): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
11-25 19:00:14.065: W/System.err(388): at dalvik.system.NativeStart.main(Native Method)
11-25 19:19:45.285: D/dalvikvm(388): GC_CONCURRENT freed 349K, 7% free 6380K/6791K, paused 10ms+2ms
11-25 19:26:27.115: I/dalvikvm(388): Jit: resizing JitTable from 512 to 1024
11-25 19:49:48.055: D/dalvikvm(388): GC_CONCURRENT freed 419K, 8% free 6378K/6919K, paused 7ms+2ms
11-25 20:19:58.565: D/dalvikvm(388): GC_CONCURRENT freed 419K, 8% free 6378K/6919K, paused 7ms+2ms
11-25 20:45:27.594: I/dalvikvm(388): Jit: resizing JitTable from 1024 to 2048
11-25 20:50:09.304: D/dalvikvm(388): GC_CONCURRENT freed 419K, 8% free 6378K/6919K, paused 7ms+3ms
11-25 21:20:19.785: D/dalvikvm(388): GC_CONCURRENT freed 419K, 8% free 6378K/6919K, paused 4ms+2ms
11-25 21:50:29.924: D/dalvikvm(388): GC_CONCURRENT freed 419K, 8% free 6378K/6919K, paused 8ms+5ms
11-25 22:20:40.565: D/dalvikvm(388): GC_CONCURRENT freed 419K, 8% free 6378K/6919K, paused 8ms+3ms
11-25 22:50:50.675: D/dalvikvm(388): GC_CONCURRENT freed 419K, 8% free 6378K/6919K, paused 7ms+2ms
11-25 23:21:00.474: D/dalvikvm(388): GC_CONCURRENT freed 419K, 8% free 6378K/6919K, paused 5ms+4ms
11-25 23:51:10.485: D/dalvikvm(388): GC_CONCURRENT freed 419K, 8% free 6378K/6919K, paused 11ms+3ms
11-26 00:21:20.725: D/dalvikvm(388): GC_CONCURRENT freed 419K, 8% free 6378K/6919K, paused 8ms+2ms
11-26 00:51:30.835: D/dalvikvm(388): GC_CONCURRENT freed 419K, 8% free 6378K/6919K, paused 8ms+3ms
11-26 01:21:41.254: D/dalvikvm(388): GC_CONCURRENT freed 419K, 8% free 6378K/6919K, paused 12ms+4ms
11-26 01:48:27.275: W/System.err(388): java.lang.NullPointerException
11-26 01:48:27.275: W/System.err(388): at net.wipp.ece.ClAct$1.onClick(ClAct.java:54)
11-26 01:48:27.275: W/System.err(388): at android.view.View.performClick(View.java:3110)
11-26 01:48:27.275: W/System.err(388): at android.view.View$PerformClick.run(View.java:11934)
11-26 01:48:27.275: W/System.err(388): at android.os.Handler.handleCallback(Handler.java:587)
11-26 01:48:27.275: W/System.err(388): at android.os.Handler.dispatchMessage(Handler.java:92)
11-26 01:48:27.285: W/System.err(388): at android.os.Looper.loop(Looper.java:132)
11-26 01:48:27.285: W/System.err(388): at android.app.ActivityThread.main(ActivityThread.java:4123)
11-26 01:48:27.285: W/System.err(388): at java.lang.reflect.Method.invokeNative(Native Method)
11-26 01:48:27.285: W/System.err(388): at java.lang.reflect.Method.invoke(Method.java:491)
11-26 01:48:27.295: W/System.err(388): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
11-26 01:48:27.295: W/System.err(388): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
11-26 01:48:27.295: W/System.err(388): at dalvik.system.NativeStart.main(Native Method)
11-26 01:48:32.734: W/System.err(388): java.lang.NullPointerException
11-26 01:48:32.744: W/System.err(388): at net.wipp.ece.ClAct$1.onClick(ClAct.java:54)
11-26 01:48:32.744: W/System.err(388): at android.view.View.performClick(View.java:3110)
11-26 01:48:32.744: W/System.err(388): at android.view.View$PerformClick.run(View.java:11934)
11-26 01:48:32.744: W/System.err(388): at android.os.Handler.handleCallback(Handler.java:587)
11-26 01:48:32.744: W/System.err(388): at android.os.Handler.dispatchMessage(Handler.java:92)
11-26 01:48:32.744: W/System.err(388): at android.os.Looper.loop(Looper.java:132)
11-26 01:48:32.744: W/System.err(388): at android.app.ActivityThread.main(ActivityThread.java:4123)
11-26 01:48:32.744: W/System.err(388): at java.lang.reflect.Method.invokeNative(Native Method)
11-26 01:48:32.744: W/System.err(388): at java.lang.reflect.Method.invoke(Method.java:491)
11-26 01:48:32.744: W/System.err(388): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
11-26 01:48:32.754: W/System.err(388): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
11-26 01:48:32.754: W/System.err(388): at dalvik.system.NativeStart.main(Native Method)
11-26 01:48:32.945: W/System.err(388): java.lang.NullPointerException
11-26 01:48:32.945: W/System.err(388): at net.wipp.ece.ClAct$1.onClick(ClAct.java:54)
11-26 01:48:32.945: W/System.err(388): at android.view.View.performClick(View.java:3110)
11-26 01:48:32.945: W/System.err(388): at android.view.View$PerformClick.run(View.java:11934)
11-26 01:48:32.945: W/System.err(388): at android.os.Handler.handleCallback(Handler.java:587)
11-26 01:48:32.955: W/System.err(388): at android.os.Handler.dispatchMessage(Handler.java:92)
11-26 01:48:32.955: W/System.err(388): at android.os.Looper.loop(Looper.java:132)
11-26 01:48:32.955: W/System.err(388): at android.app.ActivityThread.main(ActivityThread.java:4123)
11-26 01:48:32.955: W/System.err(388): at java.lang.reflect.Method.invokeNative(Native Method)
11-26 01:48:32.955: W/System.err(388): at java.lang.reflect.Method.invoke(Method.java:491)
11-26 01:48:32.955: W/System.err(388): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
11-26 01:48:32.955: W/System.err(388): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
11-26 01:48:32.955: W/System.err(388): at dalvik.system.NativeStart.main(Native Method)
11-26 01:48:33.116: W/System.err(388): java.lang.NullPointerException
11-26 01:48:33.116: W/System.err(388): at net.wipp.ece.ClAct$1.onClick(ClAct.java:54)
11-26 01:48:33.116: W/System.err(388): at android.view.View.performClick(View.java:3110)
11-26 01:48:33.116: W/System.err(388): at android.view.View$PerformClick.run(View.java:11934)
11-26 01:48:33.116: W/System.err(388): at android.os.Handler.handleCallback(Handler.java:587)
11-26 01:48:33.116: W/System.err(388): at android.os.Handler.dispatchMessage(Handler.java:92)
11-26 01:48:33.116: W/System.err(388): at android.os.Looper.loop(Looper.java:132)
11-26 01:48:33.125: W/System.err(388): at android.app.ActivityThread.main(ActivityThread.java:4123)
11-26 01:48:33.125: W/System.err(388): at java.lang.reflect.Method.invokeNative(Native Method)
11-26 01:48:33.125: W/System.err(388): at java.lang.reflect.Method.invoke(Method.java:491)
11-26 01:48:33.125: W/System.err(388): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
11-26 01:48:33.125: W/System.err(388): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
11-26 01:48:33.155: W/System.err(388): at dalvik.system.NativeStart.main(Native Method)
11-26 01:48:33.195: D/dalvikvm(388): GC_CONCURRENT freed 415K, 8% free 6382K/6919K, paused 4ms+2ms
11-26 01:48:33.305: W/System.err(388): java.lang.NullPointerException
11-26 01:48:33.305: W/System.err(388): at net.wipp.ece.ClAct$1.onClick(ClAct.java:54)
11-26 01:48:33.305: W/System.err(388): at android.view.View.performClick(View.java:3110)
11-26 01:48:33.305: W/System.err(388): at android.view.View$PerformClick.run(View.java:11934)
11-26 01:48:33.305: W/System.err(388): at android.os.Handler.handleCallback(Handler.java:587)
11-26 01:48:33.305: W/System.err(388): at android.os.Handler.dispatchMessage(Handler.java:92)
11-26 01:48:33.305: W/System.err(388): at android.os.Looper.loop(Looper.java:132)
11-26 01:48:33.305: W/System.err(388): at android.app.ActivityThread.main(ActivityThread.java:4123)
11-26 01:48:33.305: W/System.err(388): at java.lang.reflect.Method.invokeNative(Native Method)
11-26 01:48:33.305: W/System.err(388): at java.lang.reflect.Method.invoke(Method.java:491)
11-26 01:48:33.305: W/System.err(388): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
11-26 01:48:33.315: W/System.err(388): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
11-26 01:48:33.315: W/System.err(388): at dalvik.system.NativeStart.main(Native Method)
11-26 01:48:33.455: W/System.err(388): java.lang.NullPointerException
11-26 01:48:33.465: W/System.err(388): at net.wipp.ece.ClAct$1.onClick(ClAct.java:54)
11-26 01:48:33.465: W/System.err(388): at android.view.View.performClick(View.java:3110)
11-26 01:48:33.465: W/System.err(388): at android.view.View$PerformClick.run(View.java:11934)
11-26 01:48:33.465: W/System.err(388): at android.os.Handler.handleCallback(Handler.java:587)
11-26 01:48:33.465: W/System.err(388): at android.os.Handler.dispatchMessage(Handler.java:92)
11-26 01:48:33.475: W/System.err(388): at android.os.Looper.loop(Looper.java:132)
11-26 01:48:33.475: W/System.err(388): at android.app.ActivityThread.main(ActivityThread.java:4123)
11-26 01:48:33.475: W/System.err(388): at java.lang.reflect.Method.invokeNative(Native Method)
11-26 01:48:33.475: W/System.err(388): at java.lang.reflect.Method.invoke(Method.java:491)
11-26 01:48:33.475: W/System.err(388): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
11-26 01:48:33.475: W/System.err(388): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
11-26 01:48:33.475: W/System.err(388): at dalvik.system.NativeStart.main(Native Method)
11-26 01:48:33.764: W/System.err(388): java.lang.NullPointerException
11-26 01:48:33.764: W/System.err(388): at net.wipp.ece.ClAct$1.onClick(ClAct.java:54)
11-26 01:48:33.764: W/System.err(388): at android.view.View.performClick(View.java:3110)
11-26 01:48:33.764: W/System.err(388): at android.view.View$PerformClick.run(View.java:11934)
11-26 01:48:33.764: W/System.err(388): at android.os.Handler.handleCallback(Handler.java:587)
11-26 01:48:33.764: W/System.err(388): at android.os.Handler.dispatchMessage(Handler.java:92)
11-26 01:48:33.774: W/System.err(388): at android.os.Looper.loop(Looper.java:132)
11-26 01:48:33.774: W/System.err(388): at android.app.ActivityThread.main(ActivityThread.java:4123)
11-26 01:48:33.774: W/System.err(388): at java.lang.reflect.Method.invokeNative(Native Method)
11-26 01:48:33.774: W/System.err(388): at java.lang.reflect.Method.invoke(Method.java:491)
11-26 01:48:33.774: W/System.err(388): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
11-26 01:48:33.774: W/System.err(388): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
11-26 01:48:33.774: W/System.err(388): at dalvik.system.NativeStart.main(Native Method)
11-26 01:50:49.035: W/System.err(472): java.net.SocketException: Permission denied
11-26 01:50:49.035: W/System.err(472): at org.apache.harmony.luni.platform.OSNetworkSystem.socket(Native Method)
11-26 01:50:49.035: W/System.err(472): at dalvik.system.BlockGuard$WrappedNetworkSystem.socket(BlockGuard.java:347)
11-26 01:50:49.035: W/System.err(472): at org.apache.harmony.luni.net.PlainSocketImpl.create(PlainSocketImpl.java:220)
11-26 01:50:49.045: W/System.err(472): at java.net.Socket.startupSocket(Socket.java:618)
11-26 01:50:49.045: W/System.err(472): at java.net.Socket.<init>(Socket.java:258)
11-26 01:50:49.045: W/System.err(472): at net.wipp.ece.ClAct.onCreate(ClAct.java:40)
11-26 01:50:49.045: W/System.err(472): at android.app.Activity.performCreate(Activity.java:4397)
11-26 01:50:49.045: W/System.err(472): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1048)
11-26 01:50:49.045: W/System.err(472): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1779)
11-26 01:50:49.045: W/System.err(472): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1831)
11-26 01:50:49.045: W/System.err(472): at android.app.ActivityThread.access$500(ActivityThread.java:122)
11-26 01:50:49.045: W/System.err(472): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1024)
11-26 01:50:49.055: W/System.err(472): at android.os.Handler.dispatchMessage(Handler.java:99)
11-26 01:50:49.055: W/System.err(472): at android.os.Looper.loop(Looper.java:132)
11-26 01:50:49.055: W/System.err(472): at android.app.ActivityThread.main(ActivityThread.java:4123)
11-26 01:50:49.055: W/System.err(472): at java.lang.reflect.Method.invokeNative(Native Method)
11-26 01:50:49.055: W/System.err(472): at java.lang.reflect.Method.invoke(Method.java:491)
11-26 01:50:49.055: W/System.err(472): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
11-26 01:50:49.055: W/System.err(472): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
11-26 01:50:49.055: W/System.err(472): at dalvik.system.NativeStart.main(Native Method)
11-26 01:50:54.375: E/Client(472): java.lang.NullPointerException
11-26 01:50:54.375: E/Client(472): at net.wipp.ece.ClAct$1.onClick(ClAct.java:54)
11-26 01:50:54.375: E/Client(472): at android.view.View.performClick(View.java:3110)
11-26 01:50:54.375: E/Client(472): at android.view.View$PerformClick.run(View.java:11934)
11-26 01:50:54.375: E/Client(472): at android.os.Handler.handleCallback(Handler.java:587)
11-26 01:50:54.375: E/Client(472): at android.os.Handler.dispatchMessage(Handler.java:92)
11-26 01:50:54.375: E/Client(472): at android.os.Looper.loop(Looper.java:132)
11-26 01:50:54.375: E/Client(472): at android.app.ActivityThread.main(ActivityThread.java:4123)
11-26 01:50:54.375: E/Client(472): at java.lang.reflect.Method.invokeNative(Native Method)
11-26 01:50:54.375: E/Client(472): at java.lang.reflect.Method.invoke(Method.java:491)
11-26 01:50:54.375: E/Client(472): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
11-26 01:50:54.375: E/Client(472): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
11-26 01:50:54.375: E/Client(472): at dalvik.system.NativeStart.main(Native Method)
11-26 01:50:54.375: W/System.err(472): java.lang.NullPointerException
11-26 01:50:54.375: W/System.err(472): at net.wipp.ece.ClAct$1.onClick(ClAct.java:54)
11-26 01:50:54.375: W/System.err(472): at android.view.View.performClick(View.java:3110)
11-26 01:50:54.375: W/System.err(472): at android.view.View$PerformClick.run(View.java:11934)
11-26 01:50:54.375: W/System.err(472): at android.os.Handler.handleCallback(Handler.java:587)
11-26 01:50:54.385: W/System.err(472): at android.os.Handler.dispatchMessage(Handler.java:92)
11-26 01:50:54.385: W/System.err(472): at android.os.Looper.loop(Looper.java:132)
11-26 01:50:54.385: W/System.err(472): at android.app.ActivityThread.main(ActivityThread.java:4123)
11-26 01:50:54.385: W/System.err(472): at java.lang.reflect.Method.invokeNative(Native Method)
11-26 01:50:54.385: W/System.err(472): at java.lang.reflect.Method.invoke(Method.java:491)
11-26 01:50:54.385: W/System.err(472): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
11-26 01:50:54.385: W/System.err(472): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
11-26 01:50:54.385: W/System.err(472): at dalvik.system.NativeStart.main(Native Method)
請發佈錯誤日誌。也發佈如何套接字被實例化 – Jack
剛剛添加日誌 – Dexters