Glide Fehler beim laden einer recyclerView „Sie müssen pass, die in einem nicht null Sicht“

Hallo, ich versuche eine Tabelle füllen RecyclerView mit einer Reihe von Bildern.
Zu tun, dass ich fetch Bild-urls aus dem web und laden Sie Sie in eine Liste<>. Das problem ist, dass anscheinend die Bildansicht Verweis, dass der adapter bekommt null ist. Dies ist der code:

private class ShowHolder extends RecyclerView.ViewHolder {
        public ImageView mImageView;
        public ProgressBar progressBar;

        public ShowHolder(LayoutInflater inflater, ViewGroup container) {
            super(inflater.inflate(R.layout.list_item_row, container, false));
            mImageView = (ImageView) itemView.findViewById(R.id.imageView);
            progressBar = (ProgressBar) itemView.findViewById(R.id.progress);
        }
    }

    private class ShowAdapter extends RecyclerView.Adapter<ShowHolder> {
        private List<Show> mShows;

        public ShowAdapter(List<Show> shows) {
            mShows = shows;
        }

        @Override
        public ShowHolder onCreateViewHolder(ViewGroup parent, int viewType) {
            LayoutInflater layoutInflater = LayoutInflater.from(getActivity());
            return new ShowHolder(layoutInflater, parent);
        }
        @Override
        public void onBindViewHolder(ShowHolder holder, int position) {
            Show currentShow = mShows.get(position);




            Glide.with(getActivity())
                    .load(currentShow.getImage()) //image url
                    .listener(new RequestListener<String, GlideDrawable>() {
                        @Override
                        public boolean onException(Exception e, String model, Target<GlideDrawable> target, boolean isFirstResource) {
                            return false;
                        }

                        @Override
                        public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {
                                            holder.progressBar.setVisibility(View.GONE);
                            return false;
                        }
                    })
                    .into(holder.mImageView); //error here

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

Dies ist, wie gebe ich den Bild-urls, um den adapter:

@Override
    public void onLoadFinished(Loader<List<Show>> loader, List<Show> shows) {
        //Clear the adapter of previous earthquake data
        mShowAdapter = new ShowAdapter(null);
        mShowAdapter.notifyDataSetChanged();

        //If there is a valid list of Shows, then add them to the adapter's
        //data set. This will trigger the ListView to update.
        Log.v(LOG_TAG, "[email protected]: " + shows);
        if (shows != null && !shows.isEmpty()) {
            mShowAdapter = new ShowAdapter(shows);
            mShowAdapter.notifyDataSetChanged();
            mRecyclerView.setAdapter(mShowAdapter);
        }

        pb.setVisibility(View.GONE);
    }

Stacktrace:

FATAL EXCEPTION: main
                                                               Process: com.dcs.shows, PID: 27818
                                                               java.lang.IllegalArgumentException: You must pass in a non null View
                                                                   at com.bumptech.glide.GenericRequestBuilder.into(GenericRequestBuilder.java:678)
                                                                   at com.bumptech.glide.DrawableRequestBuilder.into(DrawableRequestBuilder.java:448)
                                                                   at com.dcs.shows.ListFragment$ShowAdapter.onBindViewHolder(ListFragment.java:154)
                                                                   at com.dcs.shows.ListFragment$ShowAdapter.onBindViewHolder(ListFragment.java:118)
                                                                   at android.support.v7.widget.RecyclerView$Adapter.onBindViewHolder(RecyclerView.java:5768)
                                                                   at android.support.v7.widget.RecyclerView$Adapter.bindViewHolder(RecyclerView.java:5801)
                                                                   at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5037)
                                                                   at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:4913)
                                                                   at android.support.v7.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:2029)
                                                                   at android.support.v7.widget.GridLayoutManager.layoutChunk(GridLayoutManager.java:531)
                                                                   at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1377)
                                                                   at android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:578)
                                                                   at android.support.v7.widget.GridLayoutManager.onLayoutChildren(GridLayoutManager.java:170)
                                                                   at android.support.v7.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:3260)
                                                                   at android.support.v7.widget.RecyclerView.dispatchLayout(RecyclerView.java:3069)
                                                                   at android.support.v7.widget.RecyclerView.onLayout(RecyclerView.java:3518)
                                                                   at android.view.View.layout(View.java:16630)
                                                                   at android.view.ViewGroup.layout(ViewGroup.java:5437)
                                                                   at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1079)
                                                                   at android.view.View.layout(View.java:16630)
                                                                   at android.view.ViewGroup.layout(ViewGroup.java:5437)
                                                                   at android.widget.FrameLayout.layoutChildren(FrameLayout.java:336)
                                                                   at android.widget.FrameLayout.onLayout(FrameLayout.java:273)
                                                                   at android.view.View.layout(View.java:16630)
                                                                   at android.view.ViewGroup.layout(ViewGroup.java:5437)
                                                                   at android.support.design.widget.HeaderScrollingViewBehavior.layoutChild(HeaderScrollingViewBehavior.java:131)
                                                                   at android.support.design.widget.ViewOffsetBehavior.onLayoutChild(ViewOffsetBehavior.java:42)
                                                                   at android.support.design.widget.AppBarLayout$ScrollingViewBehavior.onLayoutChild(AppBarLayout.java:1319)
                                                                   at android.support.design.widget.CoordinatorLayout.onLayout(CoordinatorLayout.java:817)
                                                                   at android.view.View.layout(View.java:16630)
                                                                   at android.view.ViewGroup.layout(ViewGroup.java:5437)
                                                                   at android.support.v4.widget.DrawerLayout.onLayout(DrawerLayout.java:1191)
                                                                   at android.view.View.layout(View.java:16630)
                                                                   at android.view.ViewGroup.layout(ViewGroup.java:5437)
                                                                   at android.widget.FrameLayout.layoutChildren(FrameLayout.java:336)
                                                                   at android.widget.FrameLayout.onLayout(FrameLayout.java:273)
                                                                   at android.view.View.layout(View.java:16630)
                                                                   at android.view.ViewGroup.layout(ViewGroup.java:5437)
                                                                   at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1743)
                                                                   at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1586)
                                                                   at android.widget.LinearLayout.onLayout(LinearLayout.java:1495)
                                                                   at android.view.View.layout(View.java:16630)
                                                                   at android.view.ViewGroup.layout(ViewGroup.java:5437)
                                                                   at android.widget.FrameLayout.layoutChildren(FrameLayout.java:336)
                                                                   at android.widget.FrameLayout.onLayout(FrameLayout.java:273)
                                                                   at android.view.View.layout(View.java:16630)
                                                                   at android.view.ViewGroup.layout(ViewGroup.java:5437)
                                                                   at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1743)
                                                                   at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1586)
                                                                   at android.widget.LinearLayout.onLayout(LinearLayout.java:1495)
                                                                   at android.view.View.layout(View.java:16630)
                                                                   at android.view.ViewGroup.layout(ViewGroup.java:5437)
                                                                   at android.widget.FrameLayout.layoutChildren(FrameLayout.java:336)
                                                                   at android.widget.FrameLayout.onLayout(FrameLayout.java:273)
                                                                   at com.android.internal.policy.PhoneWindow$DecorView.onLayout(PhoneWindow.java:2678)
                                                                   at android.view.View.layout(View.java:16630)

Dank

InformationsquelleAutor user11230 | 2016-09-12



One Reply
  1. 1

    Ändern Sie Ihre onCerateViewHolder Methode:

        @Override
        public ShowHolder onCreateViewHolder(ViewGroup parent, int viewType) {
                LayoutInflater inflater = LayoutInflater.from(getActivity());
                View rootView = inflater.inflate(R.layout.list_item_row, parent, false);
                return new ShowHolder(rootView);
        }

    Und ändern Sie Ihre Halter-Konstruktor:

       public ShowHolder(View itemView) {
                super(itemView);
                mImageView = (ImageView) itemView.findViewById(R.id.imageView);
                progressBar = (ProgressBar) itemView.findViewById(R.id.progress);
       }
    • Hallo, ich habe versucht und der compiler sagt „es gibt keinen default-Konstruktor in“ android.Unterstützung.v7.- widget.RecyclerView.ViewHolder'“.
    • Ich aktualisiert meine Antwort.
    • Danke es hat geklappt 🙂

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert.