gpt4 book ai didi

java - 检索位图给出未知主机异常?

转载 作者:行者123 更新时间:2023-11-29 22:19:32 25 4
gpt4 key购买 nike

我正在使用这段代码从网络上获取位图

  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;
}

唯一的问题是我一直收到这个错误。我每次都尝试获取位图。错误指向我:

 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)

最佳答案

显然,您的 url 地址无效。将您的 url 手动复制到浏览器窗口中,您应该会看到相同的错误。

关于java - 检索位图给出未知主机异常?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7609409/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com