我正在使用Glide 4.x,由于URL返回404,出现了FileNotFoundException。我尝试使用RequestListener捕获异常,但它没有缓存这个异常。
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);
记录如下:
2019-03-20 17:48:07.134 32233-32233/com.zyta.zflikz W/Glide: 加载https://lh4.googleusercontent.com/-UxjwFuQRjXA/AAAAAAAAAAI/AAAAAAAAAAA/ACLGyWByUX_zz0_9075kpV4xIdPmN_dtNQ/s96-c/photo.jpg 失败,大小为[183x183],异常信息如下:class com.bumptech.glide.load.engine.GlideException: 加载资源失败,有2个原因: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),请调用GlideException#logRootCauses(String)以获取更多详细信息。其中第一个原因是 class com.bumptech.glide.load.engine.GlideException: 获取数据失败,类型为class java.io.InputStream,来源为REMOTE,有1个原因:java.io.FileNotFoundException(https://lh4.googleusercontent.com/-UxjwFuQRjXA/AAAAAAAAAAI/AAAAAAAAAAA/ACLGyWByUX_zz0_9075kpV4xIdPmN_dtNQ/s96-c/photo.jpg),请调用GlideException#logRootCauses(String)以获取更多详细信息。其中第一个原因是 class java.io.FileNotFoundException: https://lh4.googleusercontent.com/-UxjwFuQRjXA/AAAAAAAAAAI/AAAAAAAAAAA/ACLGyWByUX_zz0_9075kpV4xIdPmN_dtNQ/s96-c/photo.jpg,第二个原因是 class com.bumptech.glide.load.engine.GlideException: 获取数据失败,类型为class java.io.InputStream,来源为REMOTE,有1个原因:java.io.FileNotFoundException(https://lh4.googleusercontent.com/-UxjwFuQRjXA/AAAAAAAAAAI/AAAAAAAAAAA/ACLGyWByUX_zz0_9075kpV4xIdPmN_dtNQ/s96-c/photo.jpg),请调用GlideException#logRootCauses(String)以获取更多详细信息。其中第一个原因是 class java.io.FileNotFoundException: https://lh4.googleusercontent.com/-UxjwFuQRjXA/AAAAAAAAAAI/AAAAAAAAAAA/ACLGyWByUX_zz0_9075kpV4xIdPmN_dtNQ/s96-c/photo.jpg,第三个原因是 class com.bumptech.glide.load.engine.GlideException: 加载路径失败,类型为LoadPath{StringUri->Object->Drawable},来源为LOCAL,其中有2个原因:class com.bumptech.glide.load.engine.GlideException: 解码路径失败,类型为DecodePath{StringUri->Drawable->Drawable} 和 class com.bumptech.glide.load.engine.GlideException: 解码路径失败,类型为DecodePath{StringUri->Bitmap->Drawable}。2019-03-20 17:48:07.135 32233-32233/com.zyta.zflikz I/Glide: 根本原因之一:java.io.FileNotFoundException: https://lh4.googleusercontent.com/-UxjwFuQRjXA/AAAAAAAAAAI/AAAAAAAAAAA/ACLGyWByUX_zz0_9075kpV4xIdPmN_dtNQ/s96-c/photo.jpg,请参考以下堆栈信息:com.android.okhttp.internal.huc.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:251),com.android.okhttp.internal.huc.DelegatingHttpsURLConnection.getInputStream(DelegatingHttpsURLConnection.java:210),com.android.okhttp.internal.huc.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:26),com.bumptech.glide.load.data.HttpUrlFetcher.loadDataWithRedirects(HttpUrlFetcher.java:106),com.bumptech.glide.load.data.HttpUrlFetcher.loadData(HttpUrlFetcher.java:59),com.bumptech.glide.load.engine.SourceGenerator.startNext(SourceGenerator.java:62),com.bumptech.glide.load.engine.DecodeJob.runGenerators(DecodeJob.java
如果有人对此有修复或替代解决方案,请让我知道。