我有一個關閉時,它的觸發連接的計時器任務,問題是,有時連接實際上是打開之前被觸發,這樣的:關閉黑莓的HttpConnection上超時
try {
HttpConnection conn = getMyConnection(); // Asume this returns a valid connection object
// ... At this moment the timer triggers the worker wich closes the connection:
conn.close(); // This is done by the timeTask before conn.getResponseCode()
int mCode = conn.getResponseCode(); // BOOOMMMM!!!! EXPLOTION!!!!
// ... Rest of my code here.
} catch(Throwable e) {
System.out.println("ups..."); // This never gets called... Why?
}
當我嘗試conn.getResponseCode()
,拋出一個異常,但不是這樣,爲什麼?
我得到這個錯誤:ClientProtocol(HttpProtocolBase).transitionToState(int)
行:484和未找到源:S。
下面的帖子很好地解釋了這種情況,建議嘗試在關閉連接之前獲取responseCode或讀取輸入流。 – 2013-03-05 18:19:38