Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/193.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 无法使用异步任务从URL加载图像_Android_Image_Url_Asynchronous - Fatal编程技术网

Android 无法使用异步任务从URL加载图像

Android 无法使用异步任务从URL加载图像,android,image,url,asynchronous,Android,Image,Url,Asynchronous,我正在尝试将图像从url加载到文本视图,但无法执行此操作,他们没有错误,进度条也出现,但图像未加载到图像视图,请帮助,提前感谢 我的代码 一,。XML: 二,。java代码 允许在应用程序中轻松加载图像,通常只需一行代码 Picasso.with(context).load("http://i.imgur.com/DvpvklR.png").into(imageView); Android上加载图像的许多常见陷阱都是由 在适配器中处理ImageView回收和下载取消。 使用最少内存的复杂图像转

我正在尝试将图像从url加载到文本视图,但无法执行此操作,他们没有错误,进度条也出现,但图像未加载到图像视图,请帮助,提前感谢

我的代码

一,。XML:

二,。java代码

允许在应用程序中轻松加载图像,通常只需一行代码

Picasso.with(context).load("http://i.imgur.com/DvpvklR.png").into(imageView);
Android上加载图像的许多常见陷阱都是由

在适配器中处理ImageView回收和下载取消。 使用最少内存的复杂图像转换。 自动内存和磁盘缓存。
为什么不使用picassono我必须使用自己开发的代码,请建议问题解决方案首先不要在PostExecute中使用runOnUiThread。。所以把它拿走
private class Load_Product_Image extends
AsyncTask<Void, Drawable, Drawable> {

     private Object fetch_image(String webaddress)
    throws MalformedURLException, IOException {
URL url = new URL(webaddress);
Object content = url.getContent();
return content;
}

protected void onPreExecute() {
    super.onPreExecute();
    progressDialog = new ProgressDialog(getActivity(),ProgressDialog.THEME_TRADITIONAL);
    progressDialog.setMessage("Loading...");
    progressDialog.setIndeterminate(false);
    progressDialog.setCancelable(false);
    progressDialog.show();
}

@Override
protected Drawable doInBackground(Void... params) {

    InputStream is = null;
    try {
        is = (InputStream) this.fetch_image(image_url);// image uri
                                                        // address
                                                        // getting
                                                        // from
                                                        // previous
                                                        // toplist
                                                        // activity
                                                        // using
                                                        // intent

    } catch (MalformedURLException e) {

        e.printStackTrace();
    } catch (IOException e) {

        e.printStackTrace();
    }
    Drawable draw = Drawable.createFromStream(is, "src");
    return draw;
}

    protected void onPostExecute(final Drawable result) {
        try {
            // Display Image...
            runOnUiThread(new Runnable() {
                public void run() {


                    profile_image.setImageDrawable(result);

                }
            });
            progressDialog.dismiss();
        } catch (Exception e) {
            // nothing
        }
    }
Picasso.with(context).load("http://i.imgur.com/DvpvklR.png").into(imageView);