title: Calling Fragment from RecyclerView Adapter
body: <p>I have a recyclerView that shows a list in cardView. This recyclerview is located in one fragment that shown in a viewPager tab. I want to go to new Fragment when thumbnail in cardview is clicked.</p>
  
  <p>I implemented following <code>onBindViewHolder</code> in order to have this functionality:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>holder.thumbnail.setOnClickListener(new View.OnClickListener() {
  @Override
      public void onClick(View v) {
  
      Fragment productDetailFragment = new ProductDetailFragment();
      (FragmentActivity)mContext).getSupportFragmentManager().beginTransaction()
      .replace(R.id.grid_page_recycler_view, productDetailFragment).commit();
                  }
              }); </code></pre>
  </div>
  </div>
  </p>
  
  <p>But after running, it returns:</p>
  
  <pre><code>E/AndroidRuntime: FATAL EXCEPTION: main
                java.lang.NullPointerException
                    at android.support.v7.widget.RecyclerView.findMinMaxChildLayoutPositions(RecyclerView.java:3757)
                    at android.support.v7.widget.RecyclerView.dispatchLayoutStep1(RecyclerView.java:3494)
                    at android.support.v7.widget.RecyclerView.onMeasure(RecyclerView.java:3019)
                    at android.view.View.measure(View.java:15819)
                    at android.widget.RelativeLayout.measureChild(RelativeLayout.java:666)
                    at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:477)
                    at android.view.View.measure(View.java:15819)
                    at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1658)
                    at android.view.View.measure(View.java:15819)
                    at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:681)
                    at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:461)
                    at android.view.View.measure(View.java:15819)
                    at android.support.v4.widget.DrawerLayout.onMeasure(DrawerLayout.java:1081)
                    at android.view.View.measure(View.java:15819)
                    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4890)
                    at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
                    at android.view.View.measure(View.java:15819)
                    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4890)
                    at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1404)
                    at android.widget.LinearLayout.measureVertical(LinearLayout.java:695)
                    at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
                    at android.view.View.measure(View.java:15819)
                    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4890)
                    at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
                    at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2176)
                    at android.view.View.measure(View.java:15819)
                    at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1965)
                    at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1146)
                    at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1356)
                    at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1046)
                    at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4603)
                    at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
                    at android.view.Choreographer.doCallbacks(Choreographer.java:562)
                    at android.view.Choreographer.doFrame(Choreographer.java:532)
                    at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735)
                    at android.os.Handler.handleCallback(Handler.java:725)
                    at android.os.Handler.dispatchMessage(Handler.java:92)
                    at android.os.Looper.loop(Looper.java:137)
                    at android.app.ActivityThread.main(ActivityThread.java:5086)
                    at java.lang.reflect.Method.invokeNative(Native Method)
                    at java.lang.reflect.Method.invoke(Method.java:511)
                    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
                    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
                    at dalvik.system.NativeStart.main(Native Method)
  </code></pre>
  
  <p>What's the reason? It's notable that if I want to call another activity, it is easy to implement.</p>
  
  <p>Thanks. </p>
  
  <p>And I must say that there are several similar questions here, but I could not use them.</p>