Android 下载的图像在imageview中显示为空白

Android 下载的图像在imageview中显示为空白,android,android-asynctask,android-imageview,android-image,Android,Android Asynctask,Android Imageview,Android Image,我使用了几种不同的方法从web服务器下载图像,并将其显示在图像视图中。我面临着同样的问题,下载后图像在imageview中显示为空白。我没有达到我错的地方。我正在使用模拟器 这是我下载图像的代码 private static InputStream OpenHttpConnection(String urlString) throws IOException { InputStream in = null;

我使用了几种不同的方法从web服务器下载图像,并将其显示在图像视图中。我面临着同样的问题,下载后图像在imageview中显示为空白。我没有达到我错的地方。我正在使用模拟器

这是我下载图像的代码

    private static InputStream OpenHttpConnection(String urlString) 
        throws IOException
        {
            InputStream in = null;
            int response = -1;

            URL url = new URL(urlString); 
            URLConnection conn = url.openConnection();

            if (!(conn instanceof HttpURLConnection))                     
                throw new IOException("Not an HTTP connection");

            try{
                HttpURLConnection httpConn = (HttpURLConnection) conn;
                httpConn.setAllowUserInteraction(false);
                httpConn.setInstanceFollowRedirects(true);
                httpConn.setRequestMethod("GET");
                httpConn.connect(); 

                response = httpConn.getResponseCode();                 
                if (response == HttpURLConnection.HTTP_OK) {
                    in = httpConn.getInputStream();                                 
                }                     
            }
            catch (Exception ex)
            {
                throw new IOException("Error connecting");            
            }
            return in;     
        }
        static Bitmap DownloadImage(String URL)
        {        
            Bitmap bitmap = null;
            InputStream in = null;        
            try {
                in = OpenHttpConnection(URL);
                bitmap = BitmapFactory.decodeStream(in);
                in.close();
            } catch (IOException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }
            return bitmap;                
        }
这是我用来显示图像的代码

   private class LongOperation extends AsyncTask<String, Void, String> {



      @Override

      protected String doInBackground(String... params) {

        // perform long running operation operation

                Bitmap message_bitmap = null; 
                // Should we download the image?
                if ((image_url != null) && (!image_url.equals("")))            
                            {
                    message_bitmap = 
                         ImageDownloader.DownloadImage(image_url);

                }
                // If we didn't get the image, we're out of here
                if (message_bitmap == null) {

                    Log.d("Image", "Null hai");
                }

        return null;

      }





      @Override

      protected void onPostExecute(String result) {

        // execution of result of Long time consuming operation
          pDialog.dismiss();
          iv.setImageDrawable(message_bitmap);
          Log.d("Image", "Displayed");
      }



      /* (non-Javadoc)
               * @see android.os.AsyncTask#onPreExecute()

       */

      @Override

      protected void onPreExecute() {

      // Things to be done before execution of long running operation.
            pDialog = new ProgressDialog(CommonUtilities.this);
            pDialog.setMessage(Html.fromHtml("Please Wait..."));
            pDialog.setIndeterminate(false);
            pDialog.setCancelable(false);
            pDialog.show();
      }







    }
私有类LongOperation扩展了异步任务{
@凌驾
受保护的字符串doInBackground(字符串…参数){
//执行长时间运行操作
位图消息\u Bitmap=null;
//我们应该下载图片吗?
如果((image_url!=null)&(!image_url.equals(“”))
{
消息\u位图=
下载图像(图像的url);
}
//如果我们没有得到图像,我们就离开这里
如果(消息\u位图==null){
Log.d(“图像”、“空值”);
}
返回null;
}
@凌驾
受保护的void onPostExecute(字符串结果){
//执行耗时较长的操作的结果
pDialog.disclose();
iv.setImageDrawable(消息\u位图);
Log.d(“图像”、“显示”);
}
/*(非Javadoc)
*@see android.os.AsyncTask#onPreExecute()
*/
@凌驾
受保护的void onPreExecute(){
//在执行长时间运行操作之前要做的事情。
pDialog=newprogressdialog(CommonUtilities.this);
setMessage(Html.fromHtml(“请稍候…”);
pDialog.setUndeterminate(假);
pDialog.setCancelable(假);
pDialog.show();
}
}

我使用此代码加载img表单url

ImageView v_thumburl = (ImageView) rowView
                .findViewById(R.id.v_thumb_url);
        thumburl = temp.getString(temp.getColumnIndex("thumburl"));
        Drawable drawable = LoadImageFromWebOperations(thumburl);
        v_thumburl.setImageDrawable(drawable);

private Drawable LoadImageFromWebOperations(String url) {
    try {
        InputStream is = (InputStream) new URL(url).getContent();
        Drawable d = Drawable.createFromStream(is, "src name");
        return d;
    } catch (Exception e) {
        System.out.println("Exc=" + e);
        return null;
    }
}

我想下载的图像,显示和存储在SD卡链接只回答。我将它保存在这里,以防答案被审阅队列删除。