I am trying to load images from imgur into a simple image view using the glide library but it is throwing me this error:
2019-05-19 09:34:15.999 5714-5714/com.bottlerocket W/Glide: Load failed for https://imgur.com/a/xYQOEhQ with size [1028x525]
class com.bumptech.glide.load.engine.GlideException: Failed to load resource
There were 2 causes:
java.io.IOException(java.lang.RuntimeException: setDataSource failed: status = 0x80000000)
java.io.IOException(java.lang.RuntimeException: setDataSource failed: status = 0x80000000)
call GlideException#logRootCauses(String) for more detail
I have already tried to override the size of the image from glide .Override() and using .AsBitmap(), .AsGif(). I have also tried to load these images using the picasso library and only one image of the set loads, the one whose url ends with .gif instead of the above.
Here is my adapter :
package com.bottlerocket.gallery
import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.cardview.widget.CardView
import androidx.recyclerview.widget.RecyclerView
import com.bottlerocket.R
import com.bottlerocket.entities.Image
import com.bumptech.glide.Glide
class GalleryAdapter (
context : Context,
private val onImageSelected: (Image) -> Unit
) : RecyclerView.Adapter<GalleryAdapter.ViewHolder>() {
private val imageList: MutableList<Image> = mutableListOf()
var adapterContext = context
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
val view = LayoutInflater.from(parent.context).inflate(R.layout.image_list_item_layout, parent, false)
return ViewHolder(view)
}
override fun getItemCount(): Int {
return imageList.count()
}
fun addImages(images: List<Image>) {
imageList.addAll(images)
notifyDataSetChanged()
}
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
val image = imageList.get(position)
holder.imageName.text = image.imageTitle
Glide.with(adapterContext)
.load(image.imageLink)
.placeholder(R.drawable.placeholder)
.into(holder.imageContent)
holder.imageContainer.setOnClickListener {
onImageSelected.invoke(image)
}
}
class ViewHolder(view: View) : RecyclerView.ViewHolder(view) {
var imageContainer = view.findViewById<CardView>(R.id.image_container)
var imageName = view.findViewById<TextView>(R.id.image_title)
var imageContent = view.findViewById<ImageView>(R.id.image_content)
}
}
https://imgur.com/a/xYQOEhQ Is a webpage.
To load an image/gif file you need a plain URL which doesn't wrap around HTML or other web pages. For example:
Glide.with(adapterContext)
.load("https://i.imgur.com/i4ZEaLM.gif")
.placeholder(R.drawable.placeholder)
.into(holder.imageContent)
User contributions licensed under CC BY-SA 3.0