在当前应用程序中,我尝试将图像从FirebaseStorage下载到应用程序中。但是我总是得到相同的错误:
W/Glide: Load failed for gs://shocal-a79c4.appspot.com/-LKW8RdfjB-FhXo54clN/items/5de008bc-6ca1-483e-8371-fc4ea39bb7e3/images/image.jpg with size [680x876]
class com.bumptech.glide.load.engine.GlideException: Failed to load resource
There was 1 cause:
com.bumptech.glide.Registry$NoModelLoaderAvailableException(Failed to find any ModelLoaders for model: gs://shocal-a79c4.appspot.com/-LKW8RdfjB-FhXo54clN/items/5de008bc-6ca1-483e-8371-fc4ea39bb7e3/images/image.jpg)
call GlideException#logRootCauses(String) for more detail
我尝试了这两种解决方案:https://stackoverflow.com/a/46653041/6152620和https://stackoverflow.com/a/48762436/6152620。我添加了“ MyGlideModule”文件,但问题仍然没有改变:
我使用Glide的文件:
class YourShopItemsRecyclerAdapter(var myContext: Context,var shop_name : ArrayList<String>,var shop_item_prices : ArrayList<String>,var shop_item_images : ArrayList<String>) : RecyclerView.Adapter<YourShopItemsRecyclerAdapter.ItemViewHolder>(){
override fun onCreateViewHolder(parent: ViewGroup, p1: Int): ItemViewHolder {
val inflater = LayoutInflater.from(parent.context).inflate(R.layout.cardview_shop_item, parent,false)
return ItemViewHolder(inflater)
}
override fun getItemCount(): Int {
return shop_name.size
}
override fun onBindViewHolder(holder: ItemViewHolder, position: Int) {
holder.item_name.text = shop_name[position]
holder.item_price.text = shop_item_prices[position]
Log.i("REF",shop_item_images[position])
var storageRef = FirebaseStorage.getInstance().reference.child(shop_item_images[position])
Glide.with(myContext).load(storageRef).into(holder.item_image)
//Glide.with(myContext).load(storageRef).thumbnail(0.001f).into(holder.item_image)
}
inner class ItemViewHolder(itemView : View) : RecyclerView.ViewHolder(itemView){
var item_name : TextView = itemView.cardView_textView_shop_item
var item_price : TextView = itemView.cardView_textView_shop_item_price
var item_image : ImageView = itemView.cardView_imageView_shop_item
}
}
有人可以向我解释我在哪里出错吗?还是这种方式不起作用,我必须找到另一个解决方案来下载图像?
我的依赖关系:
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
implementation 'com.android.support:appcompat-v7:28.0.0-alpha1'
implementation 'com.android.support:design:28.0.0-alpha1'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
implementation 'com.google.android.gms:play-services-maps:15.0.1'
implementation 'com.google.firebase:firebase-database:16.0.1'
implementation 'com.google.firebase:firebase-auth:16.0.1'
implementation 'com.firebaseui:firebase-ui-storage:4.1.0'
implementation 'com.android.support:support-v4:28.0.0-rc01'
implementation 'com.android.support:recyclerview-v7:28.0.0-rc01'
implementation 'com.android.support:support-vector-drawable:28.0.0-rc02'
implementation 'com.google.firebase:firebase-storage:16.0.1'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.firebase:firebase-jobdispatcher:0.8.5'
annotationProcessor 'com.github.bumptech.glide:compiler:4.8.0'
}