Ish*_*jaz 5 android loadimage android-glide
我正在使用此代码从网络加载图像。
由于出现错误,我同时发出多个请求,FileNotFound但该文件实际上存在于服务器上。
因此我想问一下,如果滑翔失败,我如何重试滑翔请求?
public static void LoadNetworkImage(final Context context, final ImageView imageView, final String imageUrl) {
Glide.with(context).
load(imageUrl).
listener(new RequestListener<Drawable>() {
@Override
public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
//if loading fails then again make request
LoadNetworkImage(context,imageView,imageUrl);
return true;
}
@Override
public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
return false;
}
}).
into(imageView);
}
Run Code Online (Sandbox Code Playgroud)
我已经研究了这个讨论如果 Glide 失败,如何重试图像加载?但它没有帮助。
错误日志
class com.bumptech.glide.load.engine.GlideException: Failed to load resource 有 1 个原因:java.io.FileNotFoundException(No content provider: http://10.0.2.2:5000/image/tmpfhpbjdsf.png ) call GlideException #logRootCauses(String) 了解更多详情 原因 (1 of 1): class com.bumptech.glide.load.engine.GlideException: 获取数据失败,class android.content.res.AssetFileDescriptor, LOCAL, DataCacheKey{sourceKey= http:// /10.0.2.2:5000/image/tmpfhpbjdsf.png , signature=EmptySignature} 有 1 个原因:java.io.FileNotFoundException(无内容提供者:http ://10.0.2.2:5000/image/tmpfhpbjdsf.png) 调用 GlideException#logRootCauses(String) 获取更多详细信息 原因 (1 of 1):class java.io.FileNotFoundException:无内容提供者:http : //10.0.2.2 : 5000/image/tmpfhpbjdsf.png 07-30 20:51 :35.127 18903-18903/com.example.muhammadusman.project I/Glide: 根本原因 (1 of 1) java.io.FileNotFoundException: 无内容提供者: http://10.0.2.2:5000/image/tmpfhpbjdsf.png com.bumptech.glide.load.engine.DecodeJob.runWrapped(DecodeJob.java:269) 在 com.bumptech.glide.load.engine.DecodeJob.run(DecodeJob.java:230) 在 java.util.concurrent.ThreadPoolExecutor.runWorker( ThreadPoolExecutor.java:1162) 在 java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636) 在 java.lang.Thread.run(Thread.java:764) 在 com.bumptech.glide.load.engine .executor.GlideExecutor$DefaultThreadFactory$1.run(GlideExecutor.java:446) 07-30 20:51:35.127 18903-18903/com.example.muhammadusman.project D/MyMessage:再次加载 07-30 20:541:3137 -1397/? W/audio_hw_generic: 没有向 HAL 提供足够的数据,预期位置 58480553 ,只写了 58327920 07-30 20:51:38.041 18903-18903/com.example.muhammadusman.project W/Glide: Load failed for runWrapped(DecodeJob.java:269) at com.bumptech.glide.load.engine.DecodeJob.run(DecodeJob.java:230) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162) at java.util .concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636) 在 java.lang.Thread.run(Thread.java:764) 在 com.bumptech.glide.load.engine.executor.GlideExecutor$DefaultThreadFactory$1.run( GlideExecutor.java:446) 07-30 20:51:35.127 18903-18903/com.example.muhammadusman.project D/MyMessage:再次加载 07-30 20:51:37.842 1397-1397/? W/audio_hw_generic: 没有向 HAL 提供足够的数据,预期位置 58480553 ,只写了 58327920 07-30 20:51:38.041 18903-18903/com.example.muhammadusman.project W/Glide: Load failed for runWrapped(DecodeJob.java:269) at com.bumptech.glide.load.engine.DecodeJob.run(DecodeJob.java:230) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162) at java.util .concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636) 在 java.lang.Thread.run(Thread.java:764) 在 com.bumptech.glide.load.engine.executor.GlideExecutor$DefaultThreadFactory$1.run( GlideExecutor.java:446) 07-30 20:51:35.127 18903-18903/com.example.muhammadusman.project D/MyMessage:再次加载 07-30 20:51:37.842 1397-1397/? W/audio_hw_generic: 没有向 HAL 提供足够的数据,预期位置 58480553 ,只写了 58327920 07-30 20:51:38.041 18903-18903/com.example.muhammadusman.project W/Glide: Load failed for engine.DecodeJob.run(DecodeJob.java:230) 在 java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162) 在 java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636) 在 java .lang.Thread.run(Thread.java:764) 在 com.bumptech.glide.load.engine.executor.GlideExecutor$DefaultThreadFactory$1.run(GlideExecutor.java:446) 07-30 20:51:35.127 18903-18903 /com.example.muhammadusman.project D/MyMessage:再次加载 07-30 20:51:37.842 1397-1397/? W/audio_hw_generic: 没有向 HAL 提供足够的数据,预期位置 58480553 ,只写了 58327920 07-30 20:51:38.041 18903-18903/com.example.muhammadusman.project W/Glide: Load failed for engine.DecodeJob.run(DecodeJob.java:230) 在 java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162) 在 java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636) 在 java .lang.Thread.run(Thread.java:764) 在 com.bumptech.glide.load.engine.executor.GlideExecutor$DefaultThreadFactory$1.run(GlideExecutor.java:446) 07-30 20:51:35.127 18903-18903 /com.example.muhammadusman.project D/MyMessage:再次加载 07-30 20:51:37.842 1397-1397/? W/audio_hw_generic: 没有向 HAL 提供足够的数据,预期位置 58480553 ,只写了 58327920 07-30 20:51:38.041 18903-18903/com.example.muhammadusman.project W/Glide: Load failed for 1162) 在 java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636) 在 java.lang.Thread.run(Thread.java:764) 在 com.bumptech.glide.load.engine.executor.GlideExecutor $DefaultThreadFactory$1.run(GlideExecutor.java:446) 07-30 20:51:35.127 18903-18903/com.example.muhammadusman.project D/MyMessage:再次加载 07-30 20:51:37.842 1397/1333 W/audio_hw_generic: 没有向 HAL 提供足够的数据,预期位置 58480553 ,只写了 58327920 07-30 20:51:38.041 18903-18903/com.example.muhammadusman.project W/Glide: Load failed for 1162) 在 java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636) 在 java.lang.Thread.run(Thread.java:764) 在 com.bumptech.glide.load.engine.executor.GlideExecutor $DefaultThreadFactory$1.run(GlideExecutor.java:446) 07-30 20:51:35.127 18903-18903/com.example.muhammadusman.project D/MyMessage:再次加载 07-30 20:51:37.842 1397/1333 W/audio_hw_generic: 没有向 HAL 提供足够的数据,预期位置 58480553 ,只写了 58327920 07-30 20:51:38.041 18903-18903/com.example.muhammadusman.project W/Glide: Load failed for 446) 07-30 20:51:35.127 18903-18903/com.example.muhammadusman.project D/MyMessage:再次加载 07-30 20:51:37.842 1397-1397/? W/audio_hw_generic: 没有向 HAL 提供足够的数据,预期位置 58480553 ,只写了 58327920 07-30 20:51:38.041 18903-18903/com.example.muhammadusman.project W/Glide: Load failed for 446) 07-30 20:51:35.127 18903-18903/com.example.muhammadusman.project D/MyMessage:再次加载 07-30 20:51:37.842 1397-1397/? W/audio_hw_generic: 没有向 HAL 提供足够的数据,预期位置 58480553 ,只写了 58327920 07-30 20:51:38.041 18903-18903/com.example.muhammadusman.project W/Glide: Load failed for http://10.0.2.2:5000/image/tmpqklezoyk.png with size [368x268] class com.bumptech.glide.load.engine.GlideException: 无法加载资源 有 1 个原因:java.io.FileNotFoundException(No content提供者:http : //10.0.2.2 : 5000/image/tmpqklezoyk.png ) 调用 GlideException#logRootCauses(String) 获取更多详细信息 原因(1 之 1):类 com.bumptech.glide.load.engine.GlideException: Fetching data失败,类 android.content.res.AssetFileDescriptor, LOCAL, DataCacheKey{sourceKey= http://10.0.2.2:5000/image/tmpqklezoyk.png , signature=EmptySignature} 有 1 个原因:java.io.FileNotFoundException(No content提供者:http : //10.0.2.2 : 5000/image/tmpqklezoyk.png) 调用 GlideException#logRootCauses(String) 获取更多详细信息 原因 (1 of 1):class java.io.FileNotFoundException:无内容提供者:http : //10.0.2.2 : 5000/image/tmpqklezoyk.png 07-30 20:51 :38.041 18903-18903/com.example.muhammadusman.project I/Glide: 根本原因 (1 of 1) java.io.FileNotFoundException: 无内容提供者: http://10.0.2.2:5000/image/tmpqklezoyk.png 在 android.content.ContentResolver.openTypedAssetFileDescriptor(ContentResolver.java:1396) 在 android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:1247) 在 android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:1170) 在glide.load.data.AssetFileDescriptorLocalUriFetcher.loadResource(AssetFileDescriptorLocalUriFetcher.java:22) at com.bumptech.glide.load.data.AssetFileDescriptorLocalUriFetcher.loadResource(AssetFileDescriptorLocalUriFetcher.java:13) at com.bumptech.glide.load.data.AssetFileDescriptorLocalUriFetcher.loadResource(AssetFileDescriptorLocalUriFetcher.java:13) loadData(LocalUriFetcher.java:44) at com.bumptech.glide.load.engine.SourceGenerator.startNext(SourceGenerator.java:62) at com.bumptech.glide.load.engine.DecodeJob.runGenerators(DecodeJob.java:299)在 com。com.bumptech.glide.load.engine.DecodeJob.runWrapped(DecodeJob.java:269) 在 com.bumptech.glide.load.engine.DecodeJob.run(DecodeJob.java:230) 在 java.util.concurrent.ThreadPoolExecutor.runWorker( ThreadPoolExecutor.java:1162) 在 java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636) 在 java.lang.Thread.run(Thread.java:764)
这是弱处理程序库
1.将此库添加到build.gradle文件中。
2.代码如下。
代码
public static void LoadNetworkImage(final Context context, final ImageView imageView, final String imageUrl) {
final WeakHandler mHandler = new WeakHandler();
final Runnable runnable = new Runnable() {
@Override
public void run() {
LoadNetworkImage(context, imageView,imageUrl);
}
};
Glide.with(context).
load(imageUrl).
transition(DrawableTransitionOptions.withCrossFade()).
listener(new RequestListener<Drawable>() {
@Override
public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
mHandler.postDelayed(runnable,1);
return true;
}
@Override
public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
return false;
}
}).
into(imageView);
}
Run Code Online (Sandbox Code Playgroud)
请注意 ,如果您的图像加载失败,则此代码将在失败 1 MiiliSecond 后发送请求。仅当您说过该资源存在时,这才最适合您的情况。
警告 但是如果资源不存在那么这不是最好的解决方案。因为递归会无限进行。
| 归档时间: |
|
| 查看次数: |
4993 次 |
| 最近记录: |