Я получаю эту ошибку при добавлении рекламных баннеров (AdMob) с утилитой просмотра и Json Volley:
java .lang.ClassCastException: com.google. android .gms.example. Bannerrecyclerviewexample не может быть приведен к com.google. android .gms.ads.AdView
Logcat приведет меня к этому:
@Override
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
int viewType = getItemViewType(position);
switch (viewType) {
case MENU_ITEM_VIEW_TYPE:
SpiViewHolder spiViewHolder = (SpiViewHolder) holder;
SPI spi = (SPI) recyclerItems.get(position);
spiViewHolder.date.setText(spi.getDate());
spiViewHolder.league.setText(spi.getLeague());
break;
case BANNER_AD_VIEW_TYPE:
default:
AdViewHolder bannerHolder = (AdViewHolder) holder;
AdView adView = (AdView) recyclerItems.get(position);
ViewGroup adCardView = (ViewGroup) bannerHolder.itemView;
if (adCardView.getChildCount() > 0) {
adCardView.removeAllViews();
}
if (adCardView.getParent() != null) {
((ViewGroup) adView.getParent()).removeView(adView);
}
adCardView.addView(adView);
}
}