Проблема с загрузкой изображения через Glide from URL («Не удалось найти загрузчики модели для модели») - PullRequest
0 голосов
/ 13 января 2019

У меня проблема с загрузкой изображения с URL Glide. URL правильный, уже проверил ответ через Почтальон. После настройки слушателя в Glide я получил StackTree от onLoadFailed:

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

...