AlertDialog in onBindViewFolder for pop-up from Card view
<p>I am not very advanced developer. Currently I am working on an app in which the alertdialog has to be called from a clickable image in a card. I developed it like this:</p>

<pre><code>public class patient_detailsAdapter extends RecyclerView.Adapter&lt;patient_detailsAdapter.patientDetailsViewHolder&gt;{

    ArrayList&lt;patient_details&gt; patientDetailList = new ArrayList&lt;patient_details&gt;();
    Context mContext;

    public patient_detailsAdapter(ArrayList&lt;patient_details&gt; patientDetailList, Context mContext){

        this.patientDetailList = patientDetailList;
        this.mContext = mContext;

    }

    @Override
    public patientDetailsViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.patient_list_layout,parent,false);
        patientDetailsViewHolder patientDetailsViewHolder = new patientDetailsViewHolder(view);

        return patientDetailsViewHolder;
    }

    @Override
    public void onBindViewHolder(final patientDetailsViewHolder holder, int position) {

        patient_details patient = patientDetailList.get(position);
        holder.person_img.setImageResource(patient.getPatientImage());
        holder.person_name.setText(patient.getName());
        holder.person_email.setText(patient.getEmail());
        holder.callButtonImage.setImageResource(patient.getCallButtonImage());

        holder.callButtonImage.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                new AlertDialog.Builder(mContext)
                        .setTitle("ABC")
                        .setMessage("bhnshsks")
                        .setIcon(R.drawable.call_now)
                        .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                Log.i("Result","Success");
                            }
                        })
                        .setNegativeButton("No", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                Log.i("Result","Success");
                            }
                        })
                        .show();

            }
        });
    }

    @Override
    public int getItemCount() {
        return patientDetailList.size();
    }

    public static class patientDetailsViewHolder extends RecyclerView.ViewHolder{

        ImageView person_img,callButtonImage;
        TextView person_email,person_name;

        public patientDetailsViewHolder(View view){
            super(view);

            person_img = (ImageView) view.findViewById(R.id.profile_image);
            person_email = (TextView) view.findViewById(R.id.profile_email);
            person_name = (TextView) view.findViewById(R.id.profile_name);
            callButtonImage = (ImageView) view.findViewById(R.id.callButton);


        }

    }
}
</code></pre>

<p>But it is showing error:</p>

<pre><code>java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.res.Resources$Theme android.content.Context.getTheme()' on a null object reference
</code></pre>

<p>And for using v7 widget of alert dialog, I am giving theme to it:</p>

<pre><code>holder.callButtonImage.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            AlertDialog.Builder builder = new AlertDialog.Builder(mContext, R.style.MyAlertDialogStyle);
            builder.setTitle("AppCompatDialog");
            builder.setMessage("Lorem ipsum dolor...");
            builder.setPositiveButton("OK", null);
            builder.setNegativeButton("Cancel", null);
            builder.show();

        }
    });
</code></pre>

<p>Then I got the error:</p>

<pre><code>java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Object android.content.Context.getSystemService(java.lang.String)' on a null object reference
</code></pre>

<p>But the main thing is that, when I removed alert dialog, and tested onclickListener with Log.i, I got success.</p>

<p>Please help, I searched everywhere but found nothing useful.
Thanks in advance.</p>

<p><strong>Edits</strong></p>

<p>My activities are:</p>

<pre><code>public class PatientListActivity extends AppCompatActivity
    implements NavigationView.OnNavigationItemSelectedListener{

private RecyclerView recyclerView;
private RecyclerView.Adapter adapter;
private RecyclerView.LayoutManager layoutManager;
private ArrayList&lt;patient_details&gt; list ;
private Context context;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_patient_list);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    recyclerView = (RecyclerView) findViewById(R.id.recyclerView);
    list = new ArrayList&lt;patient_details&gt;();

    preparValue();

    layoutManager = new LinearLayoutManager(this);
    recyclerView.setLayoutManager(layoutManager);
    recyclerView.setHasFixedSize(true);
    adapter = new patient_detailsAdapter(list,context);
    recyclerView.setAdapter(adapter);
   }private void preparValue(){

    int[] images = new int[]{ R.drawable.abc, R.drawable.efg, R.drawable.efr};
    int[] buttonImage = new int[]{R.drawable.call_now};
    patient_details a = new patient_details(images[0],"abc@xyz.com","ABC_Name",buttonImage[0]);
    list.add(a);

    patient_details b = new patient_details(images[1],"efg@xyz.com","EFG_Name",buttonImage[0]);
    list.add(b);

    patient_details c = new patient_details(images[2],"efr@xyz.com","Leonardo Di Caprio",buttonImage[0]);
    list.add(c);

}
</code></pre>

<p>It's my activity where I instantiated the class.</p>