我似乎得到一個簡單的TCP連接之間的Java服務器應用程序和Android(我已經嘗試了模擬器和Android Dev Phone 2)。我在模擬器上得到這個錯誤「應用程序數據接收(進程com.mdog.datareceive)意外停止,請重試。」Android的TCP - 程序崩潰
原諒我,但我對android很新。所以我不知道如何調試它......但我沒有嘗試任何太複雜的東西。最終,我想嘗試「消耗」我在應用程序中收到的字節。並在後臺運行TCP ......但現在只需讓手機和計算機進行通信就會很好。
如果你能幫助我,那會很棒。
代號爲Android的一面:
public class Receive extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TextView tv = new TextView(this);
Socket connectionSocket = null;
byte[] inputHolderByteArray = new byte[5*1024];
/* Connect to Server */
try {
connectionSocket = new Socket("192.168.0.104", 11313);
} catch (UnknownHostException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
/* Send an s to server to start transmission */
try {
PrintWriter out = new PrintWriter(connectionSocket.getOutputStream(), true);
out.print('s');
out.flush();
} catch (IOException e1) {
e1.printStackTrace();
}
/* read server transmission */
try {
connectionSocket.getInputStream().read(inputHolderByteArray);
} catch (IOException e) {
e.printStackTrace();
}
tv.setText("done");
setContentView(tv);
}
}
你要實際的異常的堆棧跟蹤,你可以從logcat中得到它,無論是在Eclipse中使用DDMS角度來看,或者從命令行使用adb logcat。 – superfell 2011-01-20 04:49:53
是的,我們需要stacktrace&Mike我建議你使用'Log.e'而不是'e.printstackTrace()'來記錄錯誤。 – 100rabh 2011-01-20 05:37:21