0
我收到IOException
從我的代碼使用AndroidHttpClient
。代碼有問題嗎?無論我使用port 80
還是port 443
,以及使用Http Schema http
或https
,都會拋出代碼。問題與AndroidHttpClient
例外情況引發client.execute
...這是一個UnknownHostException
異常..我不知道爲什麼。我可以從瀏覽器中獲得服務。
// declare locals
JSONObject joResponse = new JSONObject();
String response = "";
try
{
// prepare to execute
HttpHost target = new HttpHost(hostname, Const.HTTP_PORT, Const.HTTP_SCHEME);
HttpGet get = new HttpGet();
ResponseHandler<String> responseHandler = new BasicResponseHandler();
AndroidHttpClient client = AndroidHttpClient.newInstance(null);
// execute
response = client.execute(target, get, responseHandler); // this is where the exception is thrown
joResponse = new JSONObject(response);
}
catch (ClientProtocolException e)
{
}
catch (IOException e)
{
}
catch(Exception e)
{
}
如果您收到一個例外則是在你的問題堆棧跟蹤顯示它沿着最佳實踐。它應該從'adb -logcat'中可用。 – Gray
@格雷我已經更新了這個問題以包含例外。 e.printStackTrace引發一個'Nullpointer',因爲e = null。 – Cody
'UnknownHostException'是一個'IOException'。所以你把'e.printStackTrace()'放在那裏,'e'是空的?從JVM的角度來看這是不可能的。如果它被捕獲,那麼它不是空的。 – Gray