小编aco*_*der的帖子

android java.net.ProtocolException:已建立连接

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;
}
Run Code Online (Sandbox Code Playgroud)

conn.setRequestMethod("GET")被解雇之前,Thorw异常连接已经建立.谁能给我一个解决方案

java android

1
推荐指数
1
解决办法
5110
查看次数

标签 统计

android ×1

java ×1