通过网址通过Glide加载图片时出现问题(“无法找到模型的任何ModelLoader”)

时间:2019-01-13 20:33:36

标签: android image android-glide

我无法通过Glide从URL加载图像。 URL是正确的,已经通过邮递员检查了响应。在Glide中设置侦听器后,我从onLoadFailed获得了StackTree:

01-13 21:11:50.780 20972-21099/findbookproject.k.findbook E/GlideExecutor: Request threw uncaught throwable
    com.bumptech.glide.Registry$NoModelLoaderAvailableException: Failed to find any ModelLoaders for model: findbookproject.k.findbook.data.ImageLinks@b1e32bc
        at com.bumptech.glide.Registry.getModelLoaders(Registry.java:584)
        at com.bumptech.glide.load.engine.DecodeHelper.getLoadData(DecodeHelper.java:205)
        at com.bumptech.glide.load.engine.DecodeHelper.getCacheKeys(DecodeHelper.java:223)
        at com.bumptech.glide.load.engine.ResourceCacheGenerator.startNext(ResourceCacheGenerator.java:44)
        at com.bumptech.glide.load.engine.DecodeJob.runGenerators(DecodeJob.java:302)
        at com.bumptech.glide.load.engine.DecodeJob.runWrapped(DecodeJob.java:269)
        at com.bumptech.glide.load.engine.DecodeJob.run(DecodeJob.java:233)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
        at java.lang.Thread.run(Thread.java:764)
        at com.bumptech.glide.load.engine.executor.GlideExecutor$DefaultThreadFactory$1.run(GlideExecutor.java:446)

这是我的Adapter和ViewHolder类:

public class FindAdapter extends RecyclerView.Adapter<FindAdapter.ViewHolder> 
{

    private List<Items> books = new ArrayList<>();

    public void updateBooks(List<Items> bookList){
        books.clear();
        books.addAll(bookList);
        notifyDataSetChanged();
    }


    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new ViewHolder(
                LayoutInflater.from(parent.getContext())
                .inflate(R.layout.item_anserw,parent,false)
        );

    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
    holder.setup(books.get(position));
    }


    @Override
    public int getItemCount() {
        return books.size();
    }


    class ViewHolder extends RecyclerView.ViewHolder{

        @BindView(R.id.item_book_image)
        ImageView bookImage;

        @BindView(R.id.item_anserw_description)
        TextView bookDescription;

        @BindView(R.id.item_anserw_name)
        TextView bookName;

        public ViewHolder(View itemView){
            super(itemView);
            ButterKnife.bind(this,itemView);
        }

        void setup(Items item){
            Glide.with(itemView.getContext())
                    .load(item.getVolumeInfo().getImageLinks())
                    .listener(new RequestListener<Drawable>() {
                        @Override
                        public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
                            Toast.makeText(itemView.getContext(),"failed",Toast.LENGTH_LONG).show();
                            e.printStackTrace();
                            return false;
                        }

                        @Override
                        public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
                            Toast.makeText(itemView.getContext(),"Load Complete",Toast.LENGTH_LONG).show();

                            return false;
                        }
                    })
                    .into(bookImage)
            ;

            bookDescription.setText(item.volumeInfo.description);
            bookName.setText(item.volumeInfo.title);


        }


    }
}

这是布局:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools">


    <ImageView
        android:id="@+id/item_book_image"
        android:layout_width="70dp"
        android:layout_height="70dp"
        android:layout_margin="@dimen/standard_mar"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        android:layout_marginEnd="@dimen/standard_mar"/>

    <TextView
        android:layout_marginStart="@dimen/standard_mar"
        android:id="@+id/item_anserw_name"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginTop="8dp"
        android:padding="16dp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toEndOf="@id/item_book_image"
        app:layout_constraintTop_toTopOf="parent"
        tools:text="textView 1" />

    <TextView
        android:layout_marginStart="@dimen/standard_mar"
        android:id="@+id/item_anserw_description"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:text="TextView 2"
        app:layout_constraintTop_toBottomOf="@id/item_anserw_name"
        app:layout_constraintStart_toEndOf="@id/item_book_image"
        app:layout_constraintEnd_toEndOf="parent"
        android:layout_marginBottom="8dp"
        android:padding="16dp"


    />




</android.support.constraint.ConstraintLayout>

前一段时间,我在不同的应用程序中使用了相同的Glide方法,并且运行良好。不知道是什么问题。上一次不需要实现ModelLoaders。 Glide 4.8.0版本

0 个答案:

没有答案