Am using Glide 4.x and getting FileNotFoundException as the URL returns 404. I tried to catch the exception using the RequestListener. But it is not Caching this Exception.
GlideApp.with(getApplicationContext()).load(URL).placeholder(R.mipmap.ic_launcher).listener(new RequestListener<Drawable>() {
@Override
public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
System.out.println("MainActivity.onLoadFailed"+e.getMessage());
return false;
}
@Override
public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
System.out.println("MainActivity.onResourceReady");
return false;
}
}).error(R.mipmap.ic_launcher).transform(new CircleCrop()).into(profileImage);
Log as Follows:
2019-03-20 17:48:07.134 32233-32233/com.zyta.zflikz W/Glide: Load failed for https://lh4.googleusercontent.com/-UxjwFuQRjXA/AAAAAAAAAAI/AAAAAAAAAAA/ACLGyWByUX_zz0_9075kpV4xIdPmN_dtNQ/s96-c/photo.jpg with size [183x183] class com.bumptech.glide.load.engine.GlideException: Failed to load resource There were 2 causes: java.io.FileNotFoundException(https://lh4.googleusercontent.com/-UxjwFuQRjXA/AAAAAAAAAAI/AAAAAAAAAAA/ACLGyWByUX_zz0_9075kpV4xIdPmN_dtNQ/s96-c/photo.jpg) java.io.FileNotFoundException(https://lh4.googleusercontent.com/-UxjwFuQRjXA/AAAAAAAAAAI/AAAAAAAAAAA/ACLGyWByUX_zz0_9075kpV4xIdPmN_dtNQ/s96-c/photo.jpg) call GlideException#logRootCauses(String) for more detail Cause (1 of 3): class com.bumptech.glide.load.engine.GlideException: Fetching data failed, class java.io.InputStream, REMOTE There was 1 cause: java.io.FileNotFoundException(https://lh4.googleusercontent.com/-UxjwFuQRjXA/AAAAAAAAAAI/AAAAAAAAAAA/ACLGyWByUX_zz0_9075kpV4xIdPmN_dtNQ/s96-c/photo.jpg) call GlideException#logRootCauses(String) for more detail Cause (1 of 1): class java.io.FileNotFoundException: https://lh4.googleusercontent.com/-UxjwFuQRjXA/AAAAAAAAAAI/AAAAAAAAAAA/ACLGyWByUX_zz0_9075kpV4xIdPmN_dtNQ/s96-c/photo.jpg Cause (2 of 3): class com.bumptech.glide.load.engine.GlideException: Fetching data failed, class java.io.InputStream, REMOTE There was 1 cause: java.io.FileNotFoundException(https://lh4.googleusercontent.com/-UxjwFuQRjXA/AAAAAAAAAAI/AAAAAAAAAAA/ACLGyWByUX_zz0_9075kpV4xIdPmN_dtNQ/s96-c/photo.jpg) call GlideException#logRootCauses(String) for more detail Cause (1 of 1): class java.io.FileNotFoundException: https://lh4.googleusercontent.com/-UxjwFuQRjXA/AAAAAAAAAAI/AAAAAAAAAAA/ACLGyWByUX_zz0_9075kpV4xIdPmN_dtNQ/s96-c/photo.jpg Cause (3 of 3): class com.bumptech.glide.load.engine.GlideException: Failed LoadPath{StringUri->Object->Drawable}, LOCAL Cause (1 of 2): class com.bumptech.glide.load.engine.GlideException: Failed DecodePath{StringUri->Drawable->Drawable} Cause (2 of 2): class com.bumptech.glide.load.engine.GlideException: Failed DecodePath{StringUri->Bitmap->Drawable} 2019-03-20 17:48:07.135 32233-32233/com.zyta.zflikz I/Glide: Root cause (1 of 2) java.io.FileNotFoundException: https://lh4.googleusercontent.com/-UxjwFuQRjXA/AAAAAAAAAAI/AAAAAAAAAAA/ACLGyWByUX_zz0_9075kpV4xIdPmN_dtNQ/s96-c/photo.jpg at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:251) at com.android.okhttp.internal.huc.DelegatingHttpsURLConnection.getInputStream(DelegatingHttpsURLConnection.java:210) at com.android.okhttp.internal.huc.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:26) at com.bumptech.glide.load.data.HttpUrlFetcher.loadDataWithRedirects(HttpUrlFetcher.java:106) at com.bumptech.glide.load.data.HttpUrlFetcher.loadData(HttpUrlFetcher.java:59) at com.bumptech.glide.load.engine.SourceGenerator.startNext(SourceGenerator.java:62) at com.bumptech.glide.load.engine.DecodeJob.runGenerators(DecodeJob.java:302) at com.bumptech.glide.load.engine.DecodeJob.runWrapped(DecodeJob.java:272) at com.bumptech.glide.load.engine.DecodeJob.run(DecodeJob.java:233) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) at java.lang.Thread.run(Thread.java:764) at com.bumptech.glide.load.engine.executor.GlideExecutor$DefaultThreadFactory$1.run(GlideExecutor.java:446) 2019-03-20 17:48:07.137 32233-32233/com.zyta.zflikz I/Glide: Root cause (2 of 2) java.io.FileNotFoundException: https://lh4.googleusercontent.com/-UxjwFuQRjXA/AAAAAAAAAAI/AAAAAAAAAAA/ACLGyWByUX_zz0_9075kpV4xIdPmN_dtNQ/s96-c/photo.jpg at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:251) at com.android.okhttp.internal.huc.DelegatingHttpsURLConnection.getInputStream(DelegatingHttpsURLConnection.java:210) at com.android.okhttp.internal.huc.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:26) at com.bumptech.glide.load.data.HttpUrlFetcher.loadDataWithRedirects(HttpUrlFetcher.java:106) at com.bumptech.glide.load.data.HttpUrlFetcher.loadData(HttpUrlFetcher.java:59) at com.bumptech.glide.load.engine.SourceGenerator.startNext(SourceGenerator.java:62) at com.bumptech.glide.load.engine.DecodeJob.runGenerators(DecodeJob.java:302) at com.bumptech.glide.load.engine.DecodeJob.onDataFetcherFailed(DecodeJob.java:397) at com.bumptech.glide.load.engine.SourceGenerator.onLoadFailed(SourceGenerator.java:119) at com.bumptech.glide.load.data.HttpUrlFetcher.loadData(HttpUrlFetcher.java:65) at com.bumptech.glide.load.engine.SourceGenerator.startNext(SourceGenerator.java:62) at com.bumptech.glide.load.engine.DecodeJob.runGenerators(DecodeJob.java:302) at com.bumptech.glide.load.engine.DecodeJob.runWrapped(DecodeJob.java:272) at com.bumptech.glide.load.engine.DecodeJob.run(DecodeJob.java:233) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) at java.lang.Thread.run(Thread.java:764) at com.bumptech.glide.load.engine.executor.GlideExecutor$DefaultThreadFactory$1.run(GlideExecutor.java:446) 2019-03-20 17:48:07.138 32233-32233/com.zyta.zflikz I/System.out: MainActivity.onLoadFailedFailed to load resource
Please let me know if anybody has a Fix or Alternate Solution for this.