Glide 加载资源失败

Glide failed to load resource

我想使用 glide

从服务器加载图像时遇到问题

这是我的代码

Glide.with(ImagePreviewActivity.this).load(path).into(img);

这是 logcat :

W/Glide: Load failed for 
http://localhost/AndroidFileUpload/file/IMG_20171128_153602.JPEG with size 
[720x1120]
                                                    class 
com.bumptech.glide.load.engine.GlideException: Failed to load resource
                                                      Cause (1 of 1): class 
com.bumptech.glide.load.engine.GlideException: Fetching data failed, class 
java.io.InputStream, REMOTE
                                                        Cause (1 of 1): 
class com.bumptech.glide.load.engine.GlideException: Fetch failed
                                                          Cause (1 of 1): 
class java.net.ConnectException: failed to connect to localhost/127.0.0.1 
(port 80) after 2500ms: isConnected failed: ECONNREFUSED (Connection refused)

如何解决这个问题?如有任何建议,我们将不胜感激。

检查日志中的这一行

class java.net.ConnectException: failed to connect to localhost/127.0.0.1

这意味着您的图像路径在您的本地主机上。如果您 运行 在模拟器上,则您的应用程序的本地主机就是模拟器。要访问桌面,请使用特殊 IP 10.0.2.2。如果您 运行 在设备上,本地主机将是设备 - 通过本地网络 IP 连接到桌面。

这可能会产生问题。所以,glide加载图片失败。

 - Glide.with(context)
                       .load(Zonelist.get(position)
                               .getZone_picture_url_3x()).apply(options).listener(new
   RequestListener<Drawable>() {
                   @Override
                   public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
                       new Handler().post(new Runnable() {
                           @Override
                           public void run() {
                               Glide.with(context)
                                       .load(Zonelist.get(position)
                                               .getZone_picture_url_3x())
                                       .into(imageView);
                           }

                       });
                       return false;
                   }

                   @Override
                   public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean
   isFirstResource) {
                       return false;
                   }
               }).into(imageView);
           }