I'm using glide in my android project. And images doesn't loading. I get "class com.bumptech.glide.load.engine.GlideException: Failed to load resource" error. And a photo url from the internet it is works.
inner class PetViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
private val nameText: TextView = itemView.findViewById(R.id.petNameTextView)
private val petImage: ImageView = itemView.findViewById(R.id.petImageView)
fun bind(pet: Pet) {
nameText.text = pet.Name
Glide.with(itemView.context)
.load("/Users/macbookair/Desktop/evcil_hayvan_app/uploads/pet_29022024004317.jpg")
.listener(object : RequestListener<Drawable> {
override fun onLoadFailed(
e: GlideException?,
model: Any?,
target: Target<Drawable>?,
isFirstResource: Boolean
): Boolean {
Log.e("Glide", "Image loading failed", e)
return false
}
override fun onResourceReady(
resource: Drawable?,
model: Any?,
target: Target<Drawable>?,
dataSource: DataSource?,
isFirstResource: Boolean
): Boolean {
//başarılı yükleme durumunda burası çalışacak
return false
}
})
.into(petImage)
}
}
Log as Follows:
Image loading failed
class com.bumptech.glide.load.engine.GlideException: Failed to load resource
There were 3 causes:
java.io.FileNotFoundException(/Users/macbookair/Desktop/evcil_hayvan_app/uploads/pet_29022024004317.jpg: open failed: ENOENT (No such file or directory))
java.io.FileNotFoundException(open failed: ENOENT (No such file or directory))
java.io.FileNotFoundException(open failed: ENOENT (No such file or directory))
call GlideException#logRootCauses(String) for more detail
Cause (1 of 3): class com.bumptech.glide.load.engine.GlideException: Fetching data failed, class java.io.InputStream, LOCAL
There was 1 cause:
java.io.FileNotFoundException(/Users/macbookair/Desktop/evcil_hayvan_app/uploads/pet_29022024004317.jpg: open failed: ENOENT (No such file or directory))
call GlideException#logRootCauses(String) for more detail
Cause (1 of 1): class com.bumptech.glide.load.engine.GlideException: Fetch failed
I can't get a photo from local. Please help me.
/Users/macbookair/Desktop/evcil_hayvan_app/uploads/pet_29022024004317.jpgwould appear to be a filesystem path for a macOS machine.Your code is for an Android app. macOS does not run Android apps. Android does not use macOS filesystem paths.
Your
load()call needs to reference something that the Android app can reach. It cannot reach into your macOS machine via a filesystem path. So, perhaps instead upload your image to a Web server and use anhttps://URL withload().