dismiss ProgressDialog and show Toast from AsyncTask thread
<p>This is the wireframe of how my class is built:</p>

<pre><code>public class HelloWorldActivity extends Activity 
{
    private ProgressDialog progressdialog;

    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);        
        setContentView(R.layout.main);        
    }       

    private class AuthenticateUserTask extends AsyncTask&lt;Void,Void,String&gt;
    {
        protected String doInBackground(Void... params)
        {
            //do something  
        }

        protected void onPostExecute(String result)
        {
            if (result.equals("success"))
                //do something
           else
           {               
               progressdialog.dismiss(); //this throws a null pointer exception
               /*
               When above line is commented to allow execution of app, Toast never shows on screen
               however no errors are recorded in the log
               */
               Toast.makeText(getApplicationContext(),"Login failed",Toast.LENGTH_SHORT);
           }
        }                   
    }   

    public void login(View v)
    {       
        progressdialog.show(HelloWorldActivity.this,"","Logging in...",true);
        new AuthenticateUserTask().execute();
    }   
}
</code></pre>

<p>I'm sorry if it seems I'm asking two questions in one thread, but I suspect the solution is similar for both.</p>

<p>Within onPostExecute:<br>
 1. If login fails and I do <code>progressdialog.dismiss()</code>, a <code>null pointer exception</code> is thrown and application crashes.<br>
2. If I remove the <code>ProgressDialog</code> and attempt to show a <code>Toast</code>, nothing show up on the screen, however no exception or error is recorded either.</p>

<p><strong>EDIT</strong><br>
I found the solution to my first problem in another thread <a href="http://stackoverflow.com/questions/6327369/how-can-i-dismiss-progressdialog-in-asynctask">here</a>. 
I had to display the <code>ProgressDialog</code> in an <code>onPreExecute</code> method.</p>
