我正在使用android 2.3.3,我做了一個rss閱讀器,它工作得很好,然後我把那個簡單的rss閱讀器的代碼整合到另一個活動中,只是複製粘貼它仔細,沒有錯誤那裏。無法連接使用httpconnection android
問題是,當我在我的模擬器上運行應用程序它給我錯誤連接異常。然後,我想通過在嘗試塊中的everyline之後加入敬酒,問題在httpconnection.connect();
行。
我已經在Android清單中添加了權限,而我的logcat給出了javaio exception:error connecting
的警告。
try {
HttpURLConnection httpURLConnection = (HttpURLConnection) connection;
//Toast.makeText(this, "urlconnection passed", Toast.LENGTH_SHORT).show();
httpURLConnection.setAllowUserInteraction(false);
httpURLConnection.setInstanceFollowRedirects(true);
//Toast.makeText(this, "setting response method", Toast.LENGTH_SHORT).show();
httpURLConnection.setRequestMethod("GET");
//Toast.makeText(this, "connecting", Toast.LENGTH_SHORT).show();
httpURLConnection.connect();
Toast.makeText(this, "on response code", Toast.LENGTH_SHORT).show();
response = httpURLConnection.getResponseCode();
//Toast.makeText(this, "response code passed", Toast.LENGTH_SHORT).show();
if (response == HttpURLConnection.HTTP_OK) {
//Toast.makeText(this, "OK", Toast.LENGTH_SHORT).show();
inputStream = httpURLConnection.getInputStream();
}
} catch (Exception e) {
// TODO: handle exception
throw new IOException("Error connecting");
}
這裏它創建的對象的代碼:
URL url = new URL(UrlString);
URLConnection connection = url.openConnection();
if (!(connection instanceof HttpURLConnection))
throw new IOException("Not a HTTP connection");
請確保您的 正文 –
我已經在我的清單文件中包含了該文件 – Salik
顯示您創建連接對象的代碼 –