Glide failed to load resource

18,911

Solution 1

Check this line from your log

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

That means your image path is on your localhost. If you run on emulator, localhost for your app is emulator. To access desktop, use special IP 10.0.2.2. If you run on device, localhost will be device - connect to desktop via local network IP.

That might create an issue. So, glide failed to load image.

Solution 2

 - 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);
           }
Share:
18,911
Dwi Teguh Prasetyo
Author by

Dwi Teguh Prasetyo

Updated on June 08, 2022

Comments

  • Dwi Teguh Prasetyo
    Dwi Teguh Prasetyo almost 2 years

    I have problem when want to load image from server using glide

    this is my code

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

    and this is the 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)
    

    How to fix this problem ? Any suggestion would be appreciated thank you.

  • Dwi Teguh Prasetyo
    Dwi Teguh Prasetyo over 6 years
    so how to make it accessible from device ?
  • Samir Bhatt
    Samir Bhatt over 6 years
    Make proper url using ip.
  • Samir Bhatt
    Samir Bhatt over 6 years
    If you are accessing from emulator, check this stackoverflow.com/a/9515414/3364266
  • Dwi Teguh Prasetyo
    Dwi Teguh Prasetyo over 6 years
    ooo thank you so much. i solve my problem by using ip instead localhost
  • Samir Bhatt
    Samir Bhatt over 6 years
    Great. You can accept/upvote my answer so it will help others also.
  • Anand Savjani
    Anand Savjani over 5 years
    this is not the exact way but helpful in case of failure :)