开发者

Retrieving bitmap giving unknown host exception?

I am using this code to get a bitmap from the web

  try {
        Bitmap bitmap=null;
开发者_开发知识库        URL imageUrl = new URL(url);
        HttpURLConnection conn = (HttpURLConnection)imageUrl.openConnection();
        conn.setConnectTimeout(30000);
        conn.setReadTimeout(30000);
        InputStream is=conn.getInputStream(); ///Error is pointing me here
        OutputStream os = new FileOutputStream(f);
        Utils.CopyStream(is, os);
        os.close();
        bitmap = decodeFile(f);
        return bitmap;
    } catch (Exception ex){
       ex.printStackTrace();
       return null;
    }

The only problem is i keep getting this errror. Every to i try to get the bitmap. The error is pointing me here:

 InputStream is=conn.getInputStream();


09-30 06:54:32.512: WARN/System.err(11149):     at java.net.InetAddress.lookupHostByName(InetAddress.java:497)
09-30 06:54:32.512: WARN/System.err(11149):     at java.net.InetAddress.getAllByNameImpl(InetAddress.java:294)
09-30 06:54:32.512: WARN/System.err(11149):     at java.net.InetAddress.getAllByName(InetAddress.java:256)
09-30 06:54:32.512: WARN/System.err(11149):     at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection.<init>(HttpConnection.java:69)
09-30 06:54:32.512: WARN/System.err(11149):     at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection.<init>(HttpConnection.java:48)
09-30 06:54:32.512: WARN/System.err(11149):     at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection$Address.connect(HttpConnection.java:322)
09-30 06:54:32.512: WARN/System.err(11149):     at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnectionPool.get(HttpConnectionPool.java:89)
09-30 06:54:32.512: WARN/System.err(11149):     at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.getHttpConnection(HttpURLConnectionImpl.java:285)
09-30 06:54:32.512: WARN/System.err(11149):     at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.makeConnection(HttpURLConnectionImpl.java:267)
09-30 06:54:32.512: WARN/System.err(11149):     at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.retrieveResponse(HttpURLConnectionImpl.java:1018)
09-30 06:54:32.512: WARN/System.err(11149):     at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:512)


Obviously, your url address is not valid. Copy your url manually into a browser window, and you should see the same error.


That is a network error, it may be that you didn't add an internet permission or your connection network isn't properly set or it may be that your url is wrong.................

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜