Glide 加载图片时监听了回调,并在失败时再次加载其它图片后报错。
代码:
- Glide.with(mContext).load(imgTeacher)
- .listener(new RequestListener
() { - @Override
- public boolean onLoadFailed(@Nullable GlideException e, Object model, Target
target, boolean isFirstResource) { - return false;
- }
- @Override
- public boolean onResourceReady(Drawable resource, Object model, Target
target, DataSource dataSource, boolean isFirstResource) { - try {
- Glide.with(mContext).load(imgTeacher).into(holder.iv2);
- } catch (Exception e) {
- e.printStackTrace();
- }
- return false;
- }
- })
- .into(holder.iv2);
异常日志:
- java.lang.IllegalStateException: You can't start or clear loads in RequestListener or Target callbacks.
- If you're trying to start a fallback request when a load fails, use RequestBuilder#error(RequestBuilder). Otherwise consider posting your into() or clear() calls to the main thread using a Handler instead.
- at com.bumptech.glide.request.SingleRequest.assertNotCallingCallbacks(SingleRequest.java:305)
- at com.bumptech.glide.request.SingleRequest.begin(SingleRequest.java:217)
- at com.bumptech.glide.RequestBuilder.into(RequestBuilder.java:806)
- at com.bumptech.glide.RequestBuilder.into(RequestBuilder.java:780)
- at com.bumptech.glide.RequestBuilder.into(RequestBuilder.java:771)
- at com.xueersi.lib.imageloader.GlideLoader.into(GlideLoader.java:321)
- at com.xueersi.lib.imageloader.GlideLoader.request(GlideLoader.java:250)
- at com.xueersi.lib.imageloader.SingleConfig.show(SingleConfig.java:270)
- at com.xueersi.lib.imageloader.SingleConfig.access$2700(SingleConfig.java:23)
- at com.xueersi.lib.imageloader.SingleConfig$ConfigBuilder.into(SingleConfig.java:347)
hander.post 一下:
- Glide.with(mContext).load("")
- .listener(new RequestListener
() { - @Override
- public boolean onLoadFailed(@Nullable GlideException e, Object model, Target
target, boolean isFirstResource) { - holder.iv1.post(() -> {
- Glide.with(mContext).load(imgTeacher).into(holder.iv2);
- });
- return false;
- }
- @Override
- public boolean onResourceReady(Drawable resource, Object model, Target
target, DataSource dataSource, boolean isFirstResource) { - return false;
- }
- })
- .into(holder.iv2);