简体   繁体   English

从android上的服务器下载的图片返回null

[英]image downloaded from server on android returning null

I want to download an image from server, I am able to download some images but not all, I dont understand why. 我想从服务器下载图像,我可以下载一些图像,但不是全部,我不明白为什么。 I have search all over the net but did not find any solution. 我已经在网上搜索了,但是没有找到任何解决方案。 my code is 我的代码是

HttpURLConnection conn = (HttpURLConnection) new URL(url).openConnection();
drawable= Drawable.createFromStream(conn.getInputStream(), "");

I have also tried this code : 我也尝试过此代码:

bitmap = BitmapFactory.decodeStream(new URL(url).openConnection().getInputStream());

nothing seem to work both bitmap and drawable are null. 似乎没有任何作用位图和可绘制都为空。

Did you check the return code of the HttpURLConnection by using the getResponseCode method? 您是否使用getResponseCode方法检查HttpURLConnection的返回码? Maybe the resource wasn't found or it contains a redirect. 也许找不到资源或它包含重定向。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM