title: How to open new fragment on Recyclerview Item Click?
body: <p>I am using recycler view in a fragment. Now I want to open a new fragment on recycler view item click. I have used the following code in my recycler view adapter. Please solve my problem.</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-js lang-js prettyprint-override"><code>public void onBindViewHolder(@NonNull MyViewHolder holder, final int position) {
          holder.tv_name.setText(mData.get(position).getName());
          holder.img.setImageResource(mData.get(position).getPhoto());
  
          holder.itemView.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  AppCompatActivity activity = (AppCompatActivity) v.getContext();
                  MiscellaneousFragment miscellaneousfragment = new MiscellaneousFragment();
                  activity.getSupportFragmentManager().beginTransaction().replace(R.id.linerr, MiscellaneousFragment).addToBackStack(null).commit();
  
              }
          });</code></pre>
  </div>
  </div>
  </p>
  
  <p>But I am getting this error in Logcat.</p>
  
  <p>java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Class java.lang.Object.getClass()' on a null object reference
          at androidx.fragment.app.FragmentTransaction.doAddOp.</p>