【发布时间】:2021-03-04 15:00:14
【问题描述】:
我正在 Android Studio 中使用来自此 URL https://orteil.dashnet.org/cookieclicker/img 的图像的应用程序
此目录中的所有图片都可以使用,除了这张图片:https://orteil.dashnet.org/cookieclicker/img/buildings.png
关于这张图片的奇怪之处在于,如果我将它保存在可绘制文件夹中,它会很好地加载这张图片。当我运行它时,InputStream 行抛出“java.net.ProtocolException: Too many follow-up requests: 21”。这是我无法从目录加载的唯一图像。有人能解释一下为什么 InputStream 会为此图像抛出 ProtocolException 吗?
这是我正在运行的代码。注意——这段代码在一个新线程上运行
//src is the bad url as a string
//myBitmap is a Bitmap array
try {
URL url = new URL(src);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
InputStream input = connection.getInputStream();
myBitmap[0] = BitmapFactory.decodeStream(input);
} catch ( IOException e) {
e.printStackTrace();
}
【问题讨论】:
-
您是否已授予互联网权限?
-
使用glide直接将你的图片从url设置为imageView
-
我给了它互联网许可。我会尝试使用 glide 看看它是否有效。如果有人能解释为什么 InputStream 有问题,那将不胜感激
标签: java android image httpurlconnection android-bitmap