Attempt to invoke virtual method when displaying TOAST? : <p>when you click a button in my activity it starts/displays a <code>DatePickerDialog</code>. When the user selects a date and clicks "ok" i want to run an <code>AsyncTask</code> in the original class (the activity where the button was clicked). Everything works but i want to display to the user a TOAST when the AsyncTask is finished but it keep on getting an error when doing so.</p>

<p>Heres my code:</p>

<p>Button method in the BuyerHomePage.java</p>

<pre><code>    public void MeetingCreator(){
        CalenderImageButton =     (ImageButton)findViewById(R.id.CalenderImageButton);
    CalenderImageButton.setOnClickListener(
            new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                                DialogFragment picker = new DatePickerFragment();
                                picker.show(getFragmentManager(), "datePicker");
           }
        }
    );
}
</code></pre>

<p>DatePickerFragment.java code</p>

<pre><code> public class DatePickerFragment extends DialogFragment
    implements DatePickerDialog.OnDateSetListener {

public static String formattedDate;

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
// Use the current date as the default date in the picker
    final Calendar c = Calendar.getInstance();
    int year = c.get(Calendar.YEAR);
    int month = c.get(Calendar.MONTH);
    int day = c.get(Calendar.DAY_OF_MONTH);

// Create a new instance of DatePickerDialog and return it
    return new DatePickerDialog(getActivity(), this, year, month, day);
}

@Override
public void onDateSet(DatePicker view, int year, int month, int day) {
    Calendar c = Calendar.getInstance();
    c.set(year, month, day);

    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    formattedDate = sdf.format(c.getTime());

    BuyerHomePage Meeting = new BuyerHomePage();
    Meeting.new MeetingSender().execute();
}
}
</code></pre>

<p>BuyerHomePage.java (post method in the AsyncTask)</p>

<pre><code>@Override
    protected void onPostExecute (String result){

        if (result.equals("email sent")) {
            //This is where i get the error
            Toast.makeText(BuyerHomePage.this, "Email sent!", Toast.LENGTH_LONG).show();
        } else {
            Toast.makeText(BuyerHomePage.this, "Can't send email", Toast.LENGTH_LONG).show();
        }
    }
</code></pre>

<p>Error Logs:</p>

<pre><code>04-23 02:25:31.631 22071-22071/com.wilsapp.wilsapp E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.wilsapp.wilsapp, PID: 22071
    java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.res.Resources android.content.Context.getResources()' on a null object reference
    at android.content.ContextWrapper.getResources(ContextWrapper.java:87)
    at android.view.ContextThemeWrapper.getResources(ContextThemeWrapper.java:81)
    at android.widget.Toast.&lt;init&gt;(Toast.java:102)
    at android.widget.Toast.makeText(Toast.java:259)
    at com.wilsapp.wilsapp.BuyerHomePage$MeetingSender.onPostExecute(BuyerHomePage.java:930)
    at com.wilsapp.wilsapp.BuyerHomePage$MeetingSender.onPostExecute(BuyerHomePage.java:836)
    at android.os.AsyncTask.finish(AsyncTask.java:651)
    at android.os.AsyncTask.-wrap1(AsyncTask.java)
    at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:668)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:148)
    at android.app.ActivityThread.main(ActivityThread.java:5417)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
</code></pre>

<p>if there's any confusion or i need to explain anything please comment! Thank you!</p>
