glide icon indicating copy to clipboard operation
glide copied to clipboard

Glide throws error instead of using specified error image when loading bitmap

Open carterhudson opened this issue 3 years ago • 7 comments

Glide Version: 4.12.0

Integration libraries: com.github.bumptech.glide:okhttp3-integration:4.12.0

Device/Android Version: Android 11; any device

Issue details / Repro steps / Use case background: Trying to load a contact image as a bitmap via content URI, with fallback in case contact has no contact image:

Expectation: If Glide is unable to load anything from the contact uri, the bitmap specified in .error(...) will be used.

Actual: java.util.concurrent.ExecutionException

Glide load line / GlideModule (if any) / list Adapter code (if any):

            Glide.with(context)
                .asBitmap()
                .load(contactUri)
                .error(
                    Glide.with(context)
                        .asBitmap()
                        .load(defaultAvatar)
                )
                .submit(width, height)
                .get()
                .let { builder.setLargeIcon(it) }

Stack trace / LogCat:

java.util.concurrent.ExecutionException: com.bumptech.glide.load.engine.GlideException: Failed to load resource
There were 3 root causes:
java.io.FileNotFoundException(InputStream is null for content://com.android.contacts/contacts/3)
java.io.FileNotFoundException(Stream I/O not supported on this URI.; URI: content://com.android.contacts/contacts/3, calling user: android.uid.shared:10069, calling package is one of: [com.android.calllogbackup, com.android.providers.userdictionary, com.android.providers.contacts, com.android.providers.blockednumber])
java.io.FileNotFoundException(Stream I/O not supported on this URI.; URI: content://com.android.contacts/contacts/3, calling user: android.uid.shared:10069, calling package is one of: [com.android.calllogbackup, com.android.providers.userdictionary, com.android.providers.contacts, com.android.providers.blockednumber])
 call GlideException#logRootCauses(String) for more detail
	at com.bumptech.glide.request.RequestFutureTarget.doGet(RequestFutureTarget.java:217)
	at com.bumptech.glide.request.RequestFutureTarget.get(RequestFutureTarget.java:130)

carterhudson avatar Oct 21 '21 21:10 carterhudson

me too, only try catch? how to fix this?

charlie-captain avatar Nov 02 '21 12:11 charlie-captain

It's actually really irritating having to create the stream and check it manually, or use try-catch

carterhudson avatar Nov 15 '21 00:11 carterhudson

Same here,

In case the url is null, glide throws an exception instead of using the drawable specified in .error(...)

In case the url is an empty string or an invalid url, glide throws an exception instead of using the drawable specified in .fallback(...)

  Glide.with(this)
                .load(url) 
                .fallback(R.drawable.fallback)
                .error(R.drawable.error)
                .submit()
                .get().apply {
                    iv_image.setImageDrawable(this)
                }

Glide Version: 4.12.0

victor-munoz avatar Nov 17 '21 16:11 victor-munoz

This issue has been automatically marked as stale because it has not had activity in the last seven days. It will be closed if no further activity occurs within the next seven days. Thank you for your contributions.

stale[bot] avatar Jan 09 '22 17:01 stale[bot]

Still a problem. I've seen it triggered if a user has provided a URL that resolves to something other than an image.

nikclayton avatar Mar 24 '24 17:03 nikclayton

Is there any solution, I use GlideModule it still can't work

yakupkavak avatar Aug 30 '24 13:08 yakupkavak

fun ImageView.getUrl(url: String) { Glide.with(this) .load(url) .thumbnail( Glide.with(this) .load(R.drawable.spinnerblack) ).error(Glide.with(this).load(R.drawable.akatsuki)) .into(this) } it works

yakupkavak avatar Aug 30 '24 13:08 yakupkavak