我正在研究一個J2ME應用程序,它發出一個HTTP請求,並相應地響應收到的響應。(HttpConnection)帶觸摸手機的Connector.open(url)
下面是我對HTTP請求
public String sendHttpGet(String url, String str) throws Exception {
HttpConnection hcon = null;
DataInputStream dis = null;
StringBuffer message = new StringBuffer();
try {
hcon = (HttpConnection) Connector.open(url);
dis = new DataInputStream(hcon.openInputStream());
int ch;
while ((ch = dis.read()) != -1) {
message.append((char)ch);
}
}catch(Exception e){
}finally {
if (hcon != null) {
hcon.close();
}
if (dis != null) {
dis.close();
}
MyForm.show();
}
return message.toString();
}
這是工作的罰款在非觸摸屏設備的代碼,但是當我檢查了諾基亞500的觸控手機,
代碼執行,直到行
hcon = (HttpConnection) Connector.open(url);
沒有拋出任何異常,它最終顯示應用程序的第一個屏幕(主菜單)。
是否有任何限制或問題?
任何解決方案?
正如我在你的代碼中看到的,你正在捕獲異常而沒有記錄或拋出運行時異常。嘗試記錄這個異常,然後在這裏打印堆棧跟蹤,我們可以幫助您快速響應 – sandrozbinden 2012-02-02 12:32:56
感謝您的快速響應,我已經從上面的代碼中刪除異常消息(和日誌)以刪除額外的代碼。我通過使用Dialog顯示消息來檢查它。 – 2012-02-02 12:58:08
我認爲你的代碼是正確的。讓你檢查你的GPRS /網絡連接,設置在你的手機。 – 2012-04-14 12:22:27