title: How to call fragment from adapter class?
body: <p>When I run the code bellow the following error is displayed:</p>
  
  <blockquote>
    <p>java.lang.NullPointerException: Attempt to invoke virtual method 'android.support.v4.app.FragmentManager android.support.v7.app.AppCompatActivity.getSupportFragmentManager()' on a null object reference.</p>
  </blockquote>
  
  <p>How to call fragment from adapter class?</p>
  
  <pre><code>Additem.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View v) 
          Fragment fragment = null;
          int position=getAdapterPosition();
          if( position==0) {
              fragment = new AddtoCard_Fragment();
          }
          if (fragment != null) {
              FragmentManager fragmentManager = ((AppCompatActivity)context).getSupportFragmentManager();
              FragmentTransaction ft = fragmentManager.beginTransaction();
              fragmentManager.popBackStack();
              ft.replace(R.id.screenarea, fragment);
              ft.commit();
          }
      }
  });
  </code></pre>