Layout inflater on a custom Dialog fragment return a null pointer exception
<p>I'm trying to show a Dialog fragment with a list of all contacts in there.</p>
<p>I've made this adapter :</p>
<pre><code>package fr.nf.smsplus.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.List;

import fr.nf.smsplus.object.Contact;
import fr.nf.smsplus.R;
import fr.nf.smsplus.contactsDialogFragment;

/**
 * Created by Nicolas on 22/05/2016.
 */
public class contactListAdapter extends BaseAdapter {

    private List&lt;Contact&gt; liste;
    private static LayoutInflater inflater = null;

    public contactListAdapter(contactsDialogFragment contactsDialogFragment, List&lt;Contact&gt; liste) {
        this.liste = liste;
        //inflater = (LayoutInflater) contactsDialogFragment.getSystemService(contactsDialogFragment.LAYOUT_INFLATER_SERVICE);
    }

    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return liste.size();
    }

    @Override
    public Object getItem(int position) {
        // TODO Auto-generated method stub
        return liste.get(position);
    }

    @Override
    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        // TODO Auto-generated method stub
        Contact contact = liste.get(position);
        View vi = convertView;
        if (vi == null)
            vi = inflater.inflate(R.layout.item_contact, null);
        TextView text = (TextView) vi.findViewById(R.id.contact_name);
        text.setText(contact.getDisplayName());
        return vi;
    }
}
</code></pre>
<p>I've made this dialogfragment :</p>
<pre><code>package fr.nf.smsplus;

import android.app.AlertDialog;
import android.app.Dialog;
import android.app.DialogFragment;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.AbsListView;

import java.util.List;

import fr.nf.smsplus.adapter.contactListAdapter;
import fr.nf.smsplus.object.Contact;

/**
 * Created by Nicolas on 22/05/2016.
 */
public class contactsDialogFragment extends DialogFragment{

    List&lt;Contact&gt; liste;
    AbsListView contactList;

    public static contactsDialogFragment newInstance(List&lt;Contact&gt; liste){
        contactsDialogFragment retour = new contactsDialogFragment();
        retour.liste = liste;
        return retour;
    }

    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        // Use the Builder class for convenient dialog construction

        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());

        LayoutInflater inflater = getActivity().getLayoutInflater();
        View contactListView = inflater.inflate(R.layout.dialog_contacts, null);
        contactList = (AbsListView) contactListView.findViewById(R.id.listContacts);
        contactList.setAdapter(new contactListAdapter(this, liste));

        builder.setView(contactListView)
                .setNegativeButton(R.string.action_cancel, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        // User cancelled the dialog
                    }
                })
                .setTitle(R.string.cdf_title);;



        // Create the AlertDialog object and return it
        return builder.create();
    }
}
</code></pre>
<p>I called the dialog like this :</p>
<pre><code> fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                contactList = new ArrayList&lt;Contact&gt;();
                listContacts();

                contactsDialogFragment pickContact = contactsDialogFragment.newInstance(contactList);
                pickContact.show(getFragmentManager(), &quot;contacts&quot;);
            }
        });
</code></pre>
<p>But i will always have this error :</p>
<pre><code>java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.View android.view.LayoutInflater.inflate(int, android.view.ViewGroup)' on a null object reference at fr.nf.smsplus.adapter.contactListAdapter.getView(contactListAdapter.java:52)
</code></pre>
<p>How can i fix this problem ? Is there a problem of execution cycle (trying to inflate a inexisting element)</p>
<h1>EDIT</h1>
<p>Trying Malik way, i've modified my adapter to add the context, and i got sameerror :</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 at fr.nf.smsplus.adapter.contactListAdapter.getView(contactListAdapter.java:55)
</code></pre>
<p>I'm trying too this : <code>contactList.setAdapter(new contactListAdapter(getActivity(), liste));</code> And it will not work ! Just modifying too my adapter constructor to <code>  public contactListAdapter(Context context, List&lt;Contact&gt; liste)</code></p>