java.lang.ClassCastException:无法强制转换为RssLargeViewHolder

java.lang.ClassCastException:无法强制转换为RssLargeViewHolder,java,android,Java,Android,有人能帮我吗 我在尝试运行应用程序时遇到此错误(标题) 以下是完整的错误日志: java.lang.ClassCastException: com.tinyapps.newsly.providers.rss.RssAdapter$HighlightViewHolder cannot be cast to com.tinyapps.newsly.providers.rss.RssAdapter$RssLargeViewHolder at com.tinyapps.newsly.providers.

有人能帮我吗

我在尝试运行应用程序时遇到此错误(标题)

以下是完整的错误日志:

java.lang.ClassCastException: com.tinyapps.newsly.providers.rss.RssAdapter$HighlightViewHolder cannot be cast to com.tinyapps.newsly.providers.rss.RssAdapter$RssLargeViewHolder at com.tinyapps.newsly.providers.rss.RssAdapter.doBindViewHolder(RssAdapter.java:94)
at com.tinyapps.newsly.util.InfiniteRecyclerViewAdapter.onBindViewHolder(InfiniteRecyclerViewAdapter.java:102)
at android.support.v7.widget.RecyclerView$Adapter.onBindViewHolder(RecyclerView.java:6673)
at android.support.v7.widget.RecyclerView$Adapter.bindViewHolder(RecyclerView.java:6714)
at android.support.v7.widget.RecyclerView$Recycler.tryBindViewHolderByDeadline(RecyclerView.java:5647)
at android.support.v7.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:5913)
at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5752)
at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5748)
at android.support.v7.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:2232)
at android.support.v7.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1559)
at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1519)
at android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:614)
at android.support.v7.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:3812)
at android.support.v7.widget.RecyclerView.dispatchLayout(RecyclerView.java:3529)
at android.support.v7.widget.RecyclerView.onLayout(RecyclerView.java:4082)
at android.view.View.layout(View.java:20831)
at android.view.ViewGroup.layout(ViewGroup.java:6203)
at android.support.v4.widget.SwipeRefreshLayout.onLayout(SwipeRefreshLayout.java:606)
at android.view.View.layout(View.java:20831)
at android.view.ViewGroup.layout(ViewGroup.java:6203)
at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1083)
at android.view.View.layout(View.java:20831)
at android.view.ViewGroup.layout(ViewGroup.java:6203)
at android.support.v4.view.ViewPager.onLayout(ViewPager.java:1769)
at android.view.View.layout(View.java:20831)
at android.view.ViewGroup.layout(ViewGroup.java:6203)
at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1083)
at android.view.View.layout(View.java:20831)
at android.view.ViewGroup.layout(ViewGroup.java:6203)
at android.support.design.widget.HeaderScrollingViewBehavior.layoutChild(HeaderScrollingViewBehavior.java:132)
at android.support.design.widget.ViewOffsetBehavior.onLayoutChild(ViewOffsetBehavior.java:42)
at android.support.design.widget.AppBarLayout$ScrollingViewBehavior.onLayoutChild(AppBarLayout.java:1361)
at android.support.design.widget.CoordinatorLayout.onLayout(CoordinatorLayout.java:894)
at android.view.View.layout(View.java:20831)
at android.view.ViewGroup.layout(ViewGroup.java:6203)
at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1083)
at android.view.View.layout(View.java:20831)
at android.view.ViewGroup.layout(ViewGroup.java:6203)
at android.support.v4.widget.DrawerLayout.onLayout(DrawerLayout.java:1171)
at android.view.View.layout(View.java:20831)
at android.view.ViewGroup.layout(ViewGroup.java:6203)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
at android.view.View.layout(View.java:20831)
at android.view.ViewGroup.layout(ViewGroup.java:6203)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
at android.view.View.layout(View.java:20831)
at android.view.ViewGroup.layout(ViewGroup.java:6203)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
at android.view.View.layout(View.java:20831)
at android.view.ViewGroup.layout(ViewGroup.java:6203)
以下是我的适配器代码:

public class RssAdapter extends InfiniteRecyclerViewAdapter {

    private List<RSSItem> objects;
    private Context context;

    private static int COMPACT = 0;
    private static int NORMAL = 1;
    private final static int HEADER_IMAGE= 2;

    private RSSItem item;

    private ViewModeUtils viewModeUtils;

    public RssAdapter(Context context,
                      List<RSSItem> list) {
        super(context, null);
        this.context = context;
        this.objects = list;

        this.viewModeUtils = new ViewModeUtils(context, RssFragment.class);
    }

    @Override
    public int getViewType(int position) {
        if (position == 0 || viewModeUtils.getViewMode() == ViewModeUtils.IMMERSIVE) {
            return HEADER_IMAGE;
        }
       else if (viewModeUtils.getViewMode() == ViewModeUtils.NORMAL) {
            return NORMAL;
        } else {
            return COMPACT;
        }
    }


    @Override
    protected RecyclerView.ViewHolder getViewHolder(ViewGroup parent, int viewType) {
        if (COMPACT == viewType) {
            View itemView = LayoutInflater.from(parent.getContext())
                    .inflate(R.layout.fragment_rss_row, parent, false);
            return new RssViewHolder((itemView));
        }  else if (viewType == HEADER_IMAGE) {
                View itemView = LayoutInflater.from(parent.getContext())
                        .inflate(R.layout.listview_highlight, parent, false);
                RecyclerView.ViewHolder holder = new HighlightViewHolder(itemView);
                requestFullSpan(holder);
                return holder;
        } else if (viewType == NORMAL) {
            View itemView = LayoutInflater.from(parent.getContext())
                    .inflate(R.layout.listview_row, parent, false);
            return new RssLargeViewHolder(itemView);
        }
        return null;
    }

    @Override
    protected void doBindViewHolder(RecyclerView.ViewHolder viewHolder, final int position) {
        if (viewHolder instanceof RssViewHolder){

            RssViewHolder holder = (RssViewHolder) viewHolder;

            holder.listTitle.setText(objects.get(position).getTitle());
            holder.listPubdate.setText(objects.get(position).getPubdate());
            holder.listThumb.setImageDrawable(null);
            String thumburl = objects.get(position).getThumburl();
            loadImageIntoView(thumburl, holder.listThumb);
            setOnClickListener(holder.itemView, position);

        } else {

            RssLargeViewHolder itemHolder = (RssLargeViewHolder) viewHolder;

            itemHolder.headlineView.setText(objects.get(position).getTitle());
            itemHolder.reportedDateView.setText(objects.get(position).getPubdate());
            itemHolder.imageView.setImageBitmap(null);
            String thumburl = objects.get(position).getThumburl();
            loadImageIntoView(thumburl, itemHolder.imageView);
            setOnClickListener(itemHolder.itemView, position);

        }
    }

    private void setOnClickListener(View view, final int position){
        view.setOnClickListener(view1 -> {
            HolderActivity.startWebViewActivity(context, objects.get(position).getLink(), Config.OPEN_INLINE_EXTERNAL, false, null);
        });
    }

    private void loadImageIntoView(String thumburl, final ImageView listThumb){
        if (thumburl != null && !thumburl.equals("")) {
            //setting the image
            final ImageView imageView = listThumb; // The view Picasso is loading an image into
            final Target target = new Target() {
                @Override
                public void onBitmapLoaded(final Bitmap bitmap, Picasso.LoadedFrom from) {
                    /* Save the bitmap or do something with it here */

                    if (10 > bitmap.getWidth() || 10 > bitmap.getHeight()) {

                        Bitmap bm = BitmapFactory.decodeResource(context.getResources(), R.drawable.rounded_image_placeholder);

                        listThumb.setImageBitmap(bm);
                        listThumb.setImageResource(R.drawable.rounded_image_placeholder);
                    } else {
                        listThumb.setImageBitmap(bitmap);
                    }
                }

                @Override
                public void onBitmapFailed(Exception e, Drawable errorDrawable) {
                }

                @Override
                public void onPrepareLoad(Drawable placeHolderDrawable) {
                }
            };

            imageView.setTag(target);
            Picasso.get()
                    .load(thumburl)
                    .into(target);
        } else {
            Bitmap bm = BitmapFactory.decodeResource(context.getResources(), R.drawable.rounded_image_placeholder);

            listThumb.setImageBitmap(bm);
            listThumb.setImageResource(R.drawable.rounded_image_placeholder);
        }
    }


    @Override
    protected int getCount() {
        return objects.size();
    }

    private class RssViewHolder extends RecyclerView.ViewHolder {
        TextView listTitle;
        TextView listPubdate;
        ImageView listThumb;

        RssViewHolder(View view){
            super(view);
            this.listTitle = view.findViewById(R.id.listtitle);
            this.listPubdate = view.findViewById(R.id.listpubdate);
            this.listThumb = view.findViewById(R.id.listthumb);
        }
    }

    private static class RssLargeViewHolder extends RecyclerView.ViewHolder {
        TextView headlineView;
        TextView reportedDateView;
        ImageView imageView;

        RssLargeViewHolder(View view){
            super(view);

            this.headlineView = view.findViewById(R.id.title);
            this.reportedDateView = view.findViewById(R.id.date);
            this.imageView = view.findViewById(R.id.thumbImage);

        }
    }

    private static class HighlightViewHolder extends RecyclerView.ViewHolder {
        TextView listTitle;
        TextView listPubdate;
        ImageView listThumb;
        TextView headlineView;
        TextView reportedDateView;
        ImageView imageView;

        HighlightViewHolder(View view){
            super(view);

            this.listTitle = view.findViewById(R.id.listtitle);
            this.listPubdate = view.findViewById(R.id.listpubdate);
            this.listThumb = view.findViewById(R.id.listthumb);
            this.headlineView = view.findViewById(R.id.title);
            this.reportedDateView = view.findViewById(R.id.date);
            this.imageView = view.findViewById(R.id.thumbImage);
        }
    }
}
公共类RssAdapter扩展了InfiniteRecycleServiceAdapter{
私有列表对象;
私人语境;
私有静态int-COMPACT=0;
私有静态int NORMAL=1;
私有最终静态int头_图像=2;
私人RSSItem项目;
私有ViewModeUtils ViewModeUtils;
公共RssAdapter(上下文,
(列表){
super(上下文,null);
this.context=上下文;
this.objects=列表;
this.viewModeUtils=新的viewModeUtils(上下文,RssFragment.class);
}
@凌驾
公共int getViewType(int位置){
if(position==0 | | viewModeUtils.getViewMode()==viewModeUtils.IMMERSIVE){
返回头部图像;
}
else if(viewModeUtils.getViewMode()==viewModeUtils.NORMAL){
恢复正常;
}否则{
回归契约;
}
}
@凌驾
受保护的RecyclerView.ViewHolder getViewHolder(视图组父级,int-viewType){
if(COMPACT==viewType){
View itemView=LayoutInflater.from(parent.getContext())
.充气(R.layout.fragment\u rss\u行,父项,false);
返回新的RssViewHolder((itemView));
}else if(viewType==标题\图像){
View itemView=LayoutInflater.from(parent.getContext())
.充气(R.layout.listview_突出显示,父级,假);
RecyclerView.ViewHolder=新的HighlightViewHolder(itemView);
请求完整跨度(持有人);
报税表持有人;
}else if(viewType==NORMAL){
View itemView=LayoutInflater.from(parent.getContext())
.充气(R.layout.listview_行,父级,假);
返回新的RssLargeViewHolder(itemView);
}
返回null;
}
@凌驾
受保护的无效多BindViewHolder(RecyclerView.ViewHolder ViewHolder,最终int位置){
if(RssViewHolder的viewHolder实例){
RSSViewolder holder=(RSSViewolder)视图持有者;
holder.listTitle.settText(objects.get(position.getTitle());
holder.listPubdate.setText(objects.get(position.getPubdate());
holder.listThumb.setImageDrawable(空);
字符串thumburl=objects.get(position.getThumburl();
loadImageIntoView(thumburl,holder.listThumb);
setOnClickListener(holder.itemView,位置);
}否则{
RssLargeViewHolder itemHolder=(RssLargeViewHolder)viewHolder;
itemHolder.headlineView.setText(objects.get(position.getTitle());
itemHolder.reportedDateView.setText(objects.get(position.getPubdate());
itemHolder.imageView.setImageBitmap(空);
字符串thumburl=objects.get(position.getThumburl();
loadImageIntoView(thumburl,itemHolder.imageView);
setOnClickListener(itemHolder.itemView,位置);
}
}
私有void setOnClickListener(视图,最终int位置){
view.setOnClickListener(视图1->{
HolderActivity.startWebViewActivity(上下文,objects.get(position).getLink(),Config.OPEN\u INLINE\u EXTERNAL,false,null);
});
}
私有void loadImageIntoView(字符串thumburl,最终图像视图listThumb){
if(thumburl!=null&!thumburl.equals(“”){
//设置图像
final ImageView ImageView=listThumb;//毕加索正在将图像加载到的视图
最终目标=新目标(){
@凌驾
公共无效onBitmapLoaded(最终位图,Picasso.LoadedFrom){
/*保存位图或在此处对其执行操作*/
如果(10>位图.getWidth()| | 10>位图.getHeight()){
位图bm=BitmapFactory.decodeResource(context.getResources(),R.drawable.rounded\u image\u占位符);
setImageBitmap(bm);
setImageResource(R.drawable.rounded\u image\u占位符);
}否则{
setImageBitmap(位图);
}
}
@凌驾
public void onBitmapFailed(异常e,Drawable errorDrawable){
}
@凌驾
准备加载时的公共无效(可提取占位符可提取){
}
};
设置标签(目标);
毕加索
.load(thumburl)
.进入(目标);
}否则{
位图bm=BitmapFactory.decodeResource(context.getResources(),R.drawable.rounded\u image\u占位符);
setImageBitmap(bm);
setImageResource(R.drawable.rounded\u image\u占位符);
}
}
@凌驾
受保护的int getCount(){
返回objects.size();
}
私有类RssViewHolder扩展了RecyclerView.ViewHolder{
文本视图列表标题;
文本视图列表发布日期;
ImageView listThumb;
RSSViewolder(视图){
超级(视图);
this.listTitle=view.findViewById(R.id.listTitle);
this.listPubdate=view.findviewbyd(R.id.listPubdate);
this.listThumb=view.findViewById(R.id.listThumb);
}
}
私有静态类RssLargeViewHolder扩展了RecyclerView.ViewHolder{
文本视图标题视图;
TextView reportedDateView;
图像视图图像视图;
RssLargeViewHolder(视图){
超级(视图);
this.headlineView=view.findViewById(R.id.title);
this.reportedDateView=view.findViewById(R.id.date);
protected void doBindViewHolder(RecyclerView.ViewHolder viewHolder, final int position) {
    if (viewHolder instanceof RssViewHolder){
        RssViewHolder itemHolder = (RssViewHolder) viewHolder;
        ...
    } else {
        // Here, it can be RssLargeViewHolder or HighlightViewHolder
        RssLargeViewHolder itemHolder = (RssLargeViewHolder) viewHolder;
        ...
    }
}
protected void doBindViewHolder(RecyclerView.ViewHolder viewHolder, final int position) {
    if (viewHolder instanceof RssViewHolder){
        RssViewHolder itemHolder = (RssViewHolder) viewHolder;
        ...
    } else if (viewHolder instanceof RssLargeViewHolder) { 
        RssLargeViewHolder itemHolder = (RssLargeViewHolder) viewHolder;
        ...
    } else if (viewHolder instanceof HighlightViewHolder) {
        HighlightViewHolder itemHolder = (HighlightViewHolder) viewHolder;
        ...
    } else {
        // Log.e ("LOG_TAG", "Error.. Wrong type received");
    }
}
@Override
protected void doBindViewHolder(RecyclerView.ViewHolder viewHolder, final int position) {
    if (viewHolder instanceof RssViewHolder){

        RssViewHolder holder = (RssViewHolder) viewHolder;

        holder.listTitle.setText(objects.get(position).getTitle());
        holder.listPubdate.setText(objects.get(position).getPubdate());
        holder.listThumb.setImageDrawable(null);
        String thumburl = objects.get(position).getThumburl();
        loadImageIntoView(thumburl, holder.listThumb);
        setOnClickListener(holder.itemView, position);

    } else {

        RssLargeViewHolder itemHolder = (RssLargeViewHolder) viewHolder; //<--here

        itemHolder.headlineView.setText(objects.get(position).getTitle());
        itemHolder.reportedDateView.setText(objects.get(position).getPubdate());
        itemHolder.imageView.setImageBitmap(null);
        String thumburl = objects.get(position).getThumburl();
        loadImageIntoView(thumburl, itemHolder.imageView);
        setOnClickListener(itemHolder.itemView, position);

    }
}