title: Null pointer Exception in RecyclerViewAdapter
body: <p>The adapter was working just fine until I decided to add Native Ads, for that I made 6 changes in the adapter.</p>
  
  <ol>
  <li>added new ViewType (AD_VIEW_TYPE)</li>
  <li>added new ViewHolder (NativeExpressAdViewHolder)</li>
  <li>changed getItemViewType (made it return AD_VIEW_TYPE at every 8th position)</li>
  <li><p>added a new case in onCreateViewHolder</p>
  
  <pre><code>     switch (viewType){
  
          case AD_VIEW_TYPE:
          View nativeExpressLayoutView = LayoutInflater.from(parent.getContext())
                  .inflate(R.layout.native_express_ad_container, parent, false);
          return new NativeExpressAdViewHolder(nativeExpressLayoutView);
  </code></pre></li>
  <li><p>Added a new case to onBindViewHolder</p>
  
  <pre><code>          switch (viewType){
  
            case AD_VIEW_TYPE:
            NativeExpressAdViewHolder nativeExpressHolder = (NativeExpressAdViewHolder)holder;
            NativeExpressAdView adView = (NativeExpressAdView)arrayList.get(position);
  
          ViewGroup adCardView = (ViewGroup)nativeExpressHolder.itemView;
          adCardView.removeAllViews();
  
          if(adView.getParent() != null){
              ((ViewGroup)adView.getParent()).removeView(adView);
          }
  
          adCardView.addView(adView);
          break;
  </code></pre></li>
  <li><p>Other than the above changes, I also changed my <code>ArrayList&lt;CardSetterGetter&gt;</code> to <code>ArrayList&lt;Object&gt;</code> in Activity and Adapter too.</p></li>
  </ol>
  
  <p>Now the problem is that when I run the app, it throws <code>NullPointerException</code>.</p>
  
  <p>the logcat says</p>
  
  <pre><code> java.lang.NullPointerException: Attempt to invoke virtual method 'void android.view.View.setOnClickListener(android.view.View$OnClickListener)' on a null object reference
                                                                        at com.company.appname.adapters.RecyclerViewAdapter$RecyclerViewHolder.&lt;init&gt;(RecyclerViewAdapter.java:186)
                                                                        at com.company.appname.adapters.RecyclerViewAdapter$RecyclerViewHolder.&lt;init&gt;(RecyclerViewAdapter.java:165)
                                                                        at com.company.appname.adapters.RecyclerViewAdapter$NativeExpressAdViewHolder.&lt;init&gt;(RecyclerViewAdapter.java:150)
                                                                        at com.company.appname.adapters.RecyclerViewAdapter.onCreateViewHolder(RecyclerViewAdapter.java:84)
                                                                        at com.company.appname.adapters.RecyclerViewAdapter.onCreateViewHolder(RecyclerViewAdapter.java:48)
  </code></pre>
  
  <p>These are the part of my code where the logcat is pointing to</p>
  
  <pre><code>/*Line 48*/public class RecyclerViewAdapter extends RecyclerView.Adapter&lt;RecyclerViewAdapter.RecyclerViewHolder&gt; {
   public RecyclerViewAdapter(Context context, ArrayList&lt;Object&gt; arrayList, ArrayList&lt;String&gt; favouriteItemList, int totalCount {...}
  
   @Override
   public long getItemId(int position){...}
  
       @Override
       public RecyclerViewAdapter.RecyclerViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
  
           switch (viewType){
  
           case AD_VIEW_TYPE:
              View nativeExpressLayoutView = LayoutInflater.from(parent.getContext())
                      .inflate(R.layout.native_express_ad_container, parent, false);
   /*Line 84*/               return new NativeExpressAdViewHolder(nativeExpressLayoutView); 
  
           case MENU_ITEM_VIEW_TYPE:
  
           default:
              View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.cards, parent, false);
              return new RecyclerViewHolder(view);
          }
      }
  
       @Override
       public void onBindViewHolder(final RecyclerViewHolder holder, final int position){...}
  
           public class NativeExpressAdViewHolder extends RecyclerViewHolder{
                  NativeExpressAdViewHolder(View view){
  /*Line 150*/                    super(view);
                  }
          }
  
       @Override
       public int getItemViewType(int position){...}
  
       @Override
       public int getItemCount(){...}
  
  
  /*Line 165*/        public class RecyclerViewHolder extends RecyclerView.ViewHolder {
  
      TextView title;
      RelativeLayout relativeLayout;
      RelativeLayout cardDescription;
      SimpleDraweeView image;
      ImageView favourite_button;
      CardSetterGetter cardSetterGetter;
      ImageView share;
  
  
      private RecyclerViewHolder(View itemView) {
          super(itemView);
          title = (TextView) itemView.findViewById(R.id.image_title);
          relativeLayout = (RelativeLayout) itemView.findViewById(R.id.activity_dash_board);
          cardDescription = (RelativeLayout) itemView.findViewById(R.id.card_details);
          image = (SimpleDraweeView) itemView.findViewById(R.id.image);
          favourite_button = (ImageView) itemView.findViewById(R.id.favourite_button);
          share = (ImageView) itemView.findViewById(R.id.share);
  
   /*Line 186*/           image.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View view) {
  
                  Activity activity = (Activity) context;
                  saveInfo(constants.SERVERIP.concat(cardSetterGetter.getImageurl()), cardSetterGetter.getImageId(), cardSetterGetter.getDescription(), cardSetterGetter.getImagetitle(), cardSetterGetter.getFavourite());
                  Intent i = new Intent().setClass(context, DetailsImageviewActivity.class);
                  i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
                  context.startActivity(i);
                  activity.overridePendingTransition(R.anim.pull_from_right, R.anim.pull_out_to_right);
              }
          });
  
      }
  }
  }
  </code></pre>
  
  <p>I know what a NullPointerException is, I know the solution to those problems, but in this case it's getting hard for me to find the source and the solution of the problem. So if the solution is that simple, instead of marking the question as a duplicate, please consider helping me out with this.</p>