public static Bitmap getImage(String address) throws Exception {
Bitmap imgmap = null;
InputStream is = null;
URL url = new URL(address);
HttpURLConnection conn = (HttpURLConnection)url.openConnection();
try {
conn.setRequestMethod("GET"); >>> here was been excuted,but go to finally block
conn.setConnectTimeout(5000);
is = conn.getInputStream();
byte[] imgbytes = StreamTool.getBytes(is);
imgmap = BitmapFactory.decodeByteArray(imgbytes, 0, imgbytes.length);
} finally {
if (is != null) {
is.close();
}
if (conn != null) {
conn.disconnect();
}
}
return imgmap;
}
之前conn.setRequestMethod("GET")
被執行,thorws的異常Connection已經建立。誰可以給我一個解決方案android java.net.ProtocolException:連接已經建立
非常感謝您 – acoder
這個答案完全是胡說八道。在調用'openConnection()'之前,你沒有一個對象,你可以調用'setRequestMethod()'。您提供的鏈接沒有說明您在此聲明的內容。 – EJP