【发布时间】:2020-11-23 18:22:45
【问题描述】:
我做错了什么?我得到 200 OK 响应,但图像位图是 null。我使用Asynctask 来检索网址图像。我正在尝试将位图分配给 imageview。
有什么想法吗?
private class loadMoreListView extends AsyncTask< Void, Void, String> {
protected String doInBackground(Void... unused) {
loadingMore = true;
Bitmap mIcon11 = null;
try {
URL url1 = new URL("https://imgaz2.staticbg.com/thumb/view/oaupload/ser1/banggood/images/E4/21/c5424852-82af-47a1-8a13-54da3d1bc049.jpg");
HttpURLConnection connection = (HttpURLConnection) url1.openConnection();
connection.setReadTimeout(10000);
connection.setConnectTimeout(10000);
connection.setDoInput(true);
connection.setRequestMethod("GET");
connection.setUseCaches(false);
connection.setAllowUserInteraction(false);
connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
int responceCode = connection.getResponseCode();
Log.i("response_line", Integer.toString(responceCode));
InputStream isstream =null;
isstream=connection.getInputStream();
//inputstream named isstream returns null
mIcon11 = BitmapFactory.decodeStream(isstream);
} catch (Exception e) {
Log.e("Error", e.getMessage());
e.printStackTrace();
}
return result;
}
【问题讨论】:
-
可能是图片的分辨率太大了。尝试使用较小的图片。
-
所有图片都是这样的...需要想办法...59kb是图片300x300大小300dpi
-
您是否考虑过使用 Glide 而不是使用 AsyncTask? AsyncTask 已弃用。
-
滑行?已弃用但可以使用...问题是因为 AsyncTask 而发生的?
-
"Glide? 已弃用但可以使用" -- Glide 未被弃用。
AsyncTask已弃用。
标签: java android android-imageview httpurlconnection