Glide: Glide 4.8.0 - cannot use RequestBuilder#error(RequestBuilder)

Created on 24 Oct 2018  路  4Comments  路  Source: bumptech/glide

Like many others I have tried to retry an image load in the onLoadFailed method of the RequestListener and ended up meeting the following error

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.

I have been trying for quite some time to implement the suggestion provided in the error message

image

But for some reason it is impossible to instantiate a new RequestBuilder in order for me to use its .error method since it appears both of its constructors are protected.

image

image

The documentation lacking any examples whatsoever does not help either.

Is this on purpose or is it being done incorrectly?

Most helpful comment

Glide.with(context).load() returns a RequestBuilder.

You're expected to do something like:

Glide.with(context)
  .load(url)
  .error(
    Glide.with(context)
      .load(fallbackUrl))
  .into(imageView);

All 4 comments

Glide.with(context).load() returns a RequestBuilder.

You're expected to do something like:

Glide.with(context)
  .load(url)
  .error(
    Glide.with(context)
      .load(fallbackUrl))
  .into(imageView);

Would never have got there, thanks for the explanation.

Now that you understand better, would you be up for sending a pull request that clarifies the warning, or adding some documentation to help the next person?

Were you expecting to see an example in the error message itself? Or in the javadoc for RequestBuilder#error? Or in the docs page?

My requirement is that if the image loading fails, it should be loaded all the time in 10 seconds. How to solve this problem?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

piedpiperlol picture piedpiperlol  路  3Comments

technoir42 picture technoir42  路  3Comments

FooBarBacon picture FooBarBacon  路  3Comments

Ncit picture Ncit  路  3Comments

Anton111111 picture Anton111111  路  3Comments