1
我想在android設備上創建一個套接字連接。 但只要我寫Socket s = new Socket("192.168.1.126",3000)
並運行它給我的錯誤作爲創建套接字時出錯?
FATAL EXCEPTION: main
10-01 16:18:55.509: E/AndroidRuntime(15664): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.senddata1/com.example.senddata1.SendData1}: java.lang.NullPointerException: println needs a message
10-01 16:18:55.509: E/AndroidRuntime(15664): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1818)
10-01 16:18:55.509: E/AndroidRuntime(15664): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1834)
10-01 16:18:55.509: E/AndroidRuntime(15664): at android.app.ActivityThread.access$500(ActivityThread.java:122)
10-01 16:18:55.509: E/AndroidRuntime(15664): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1027)
10-01 16:18:55.509: E/AndroidRuntime(15664): at android.os.Handler.dispatchMessage(Handler.java:99)
10-01 16:18:55.509: E/AndroidRuntime(15664): at android.os.Looper.loop(Looper.java:132)
10-01 16:18:55.509: E/AndroidRuntime(15664): at android.app.ActivityThread.main(ActivityThread.java:4126)
10-01 16:18:55.509: E/AndroidRuntime(15664): at java.lang.reflect.Method.invokeNative(Native Method)
10-01 16:18:55.509: E/AndroidRuntime(15664): at java.lang.reflect.Method.invoke(Method.java:491)
10-01 16:18:55.509: E/AndroidRuntime(15664): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:844)
10-01 16:18:55.509: E/AndroidRuntime(15664): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
10-01 16:18:55.509: E/AndroidRuntime(15664): at dalvik.system.NativeStart.main(Native Method)
10-01 16:18:55.509: E/AndroidRuntime(15664): Caused by: java.lang.NullPointerException: println needs a message
10-01 16:18:55.509: E/AndroidRuntime(15664): at android.util.Log.println_native(Native Method)
10-01 16:18:55.509: E/AndroidRuntime(15664): at android.util.Log.e(Log.java:230)
10-01 16:18:55.509: E/AndroidRuntime(15664): at com.example.senddata1.SendData1.onCreate(SendData1.java:66)
10-01 16:18:55.509: E/AndroidRuntime(15664): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1050)
10-01 16:18:55.509: E/AndroidRuntime(15664): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1782)
10-01 16:18:55.509: E/AndroidRuntime(15664): ... 11 more
請幫助我,我面對的問題。
你應該閱讀文檔。我認爲你沒有正確使用它。 http://developer.android.com/reference/java/net/Socket.html#Socket(java.net.Proxy) – JoxTraex
似乎你正在使用'Log.e()'打印空值。你究竟打印了什麼? –