class com.bumptech.glide.load.engine.GlideException: Failed to load resource
class com.bumptech.glide.load.engine.GlideException: Failed to load resource in Android 10 only
enter image description here I got the error from logcat. I have read the above two articles. I also used the method they introduced. It still hasn’t been solved. I think there is a different solution to my problem??
com.bumptech.glide.load.engine.GlideException: Failed to load resource
There were 4 root causes:
java.lang.RuntimeException(setDataSourceCallback failed: status = 0x80000000)
java.lang.RuntimeException(setDataSourceCallback failed: status = 0x80000000)
java.lang.RuntimeException(setDataSource failed: status = 0x80000000)
java.lang.RuntimeException(setDataSource failed: status = 0x80000000)
call GlideException#logRootCauses(String) for more detail
dependencies
implementation "com.github.bumptech.glide:glide:4.12.0" annotationProcessor 'com.github.bumptech.glide:compiler:4.12.0'
marifest
<uses-permission android:name="android.permission.INTERNET"/> android:usesCleartextTraffic="true"
code
@BindingAdapter("imageUrl")
fun bindImage(imageView: ImageView,imgUrl:String?){
imgUrl?.let {
val imageUri=imgUrl.toUri().buildUpon().scheme("https").build()
Glide.with(imageView.context)
.load(imageUri)
.centerCrop()
.apply(RequestOptions()
.placeholder(R.drawable.loading_animation)
.error(R.drawable.ic_broken_image))
.listener(object :RequestListener<Drawable>{
override fun onLoadFailed(
e: GlideException?,
model: Any?,
target: Target<Drawable>?,
isFirstResource: Boolean
): Boolean {
Log.d("aa","===${e}")
return false
}
override fun onResourceReady(
resource: Drawable?,
model: Any?,
target: Target<Drawable>?,
dataSource: DataSource?,
isFirstResource: Boolean
): Boolean {
return false
}
})
.into(imageView)
}
}
layout
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<data>
<variable
name="sport"
type="com.example.retrofit2test.net.Sport" />
</data>
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/imageView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:adjustViewBounds="true"
android:scaleType="centerCrop"
app:imageUrl="@{sport.photo1}"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:srcCompat="@tools:sample/avatars" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>
</layout>
Advertisement
Answer
It is because you are turning the image url to Uri which does not exist on your device! If you give glide to load a Uri, it will check the files. And it does not exist for obvious reasons. So you do not need to convert it to uri. Instead you just pass it the imageUrl.
So, replace
Glide.with(imageView.context)
.load(imageUri)
.centerCrop()
.apply(RequestOptions()
.placeholder(R.drawable.loading_animation)
.error(R.drawable.ic_broken_image))
.listener(object :RequestListener<Drawable>{
override fun onLoadFailed(
e: GlideException?,
model: Any?,
target: Target<Drawable>?,
isFirstResource: Boolean
): Boolean {
Log.d("aa","===${e}")
return false
}
override fun onResourceReady(
resource: Drawable?,
model: Any?,
target: Target<Drawable>?,
dataSource: DataSource?,
isFirstResource: Boolean
): Boolean {
return false
}
})
.into(imageView)
with
Glide.with(imageView.context)
.load(imageUrl)
.centerCrop()
.apply(RequestOptions()
.placeholder(R.drawable.loading_animation)
.error(R.drawable.ic_broken_image))
.listener(object :RequestListener<Drawable>{
override fun onLoadFailed(
e: GlideException?,
model: Any?,
target: Target<Drawable>?,
isFirstResource: Boolean
): Boolean {
Log.d("aa","===${e}")
return false
}
override fun onResourceReady(
resource: Drawable?,
model: Any?,
target: Target<Drawable>?,
dataSource: DataSource?,
isFirstResource: Boolean
): Boolean {
return false
}
})
.into(imageView)