My simple app is set to retrieve RSS feeds when the Refresh
button is clicked.
Clicking the refresh button starts an AsyncTask
which retrieves the feeds. The AsyncTask
is a subcalss of the main activity.
Here is what my class looks like:
public class NasaDailyImage extends Activity{
public ProgressDialog modalDialog = null; //problematic
//------------------------------------------------------------------------------
@Override
protected void onCreate(Bundle savedInstanceState){
//instantiate the ProgressDialog
Button b = //get reference to button
b.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
modalDialog.show(); // show modal
Toast.makeText(getApplicationContext(), "Getting feeds", 500).show();
new AsyncRetriever().execute(new IotdHandler()); // Get the feeds !!
}
});
}
//------------------------------------------------------------------------------
public synchronized void resetDisplay(boolean parseErrorOccured,
boolean imageErrorOccured,
IotdHandler newFeeds){
if(parseErrorOccured || imageErrorOccured){
// make a Toast
// do not update display
}else{
// make a Toast
// update display
// based on new feed
}
}
//------------------------------------------------------------------------------
class AsyncRetriever extends AsyncTask<IotdHandler,Void,IotdHandler>{
@Override
protected IotdHandler doInBackground(IotdHandler... arg0) {
IotdHandler handler = arg0[0];
handler.processFeed(); // get the RSS feed data !
return handler;
}
//------------------------------------------------------------------------------
@Override
protected void onPostExecute(IotdHandler fromInBackground){
resetDisplay( // call to update the display
fromInBackground.errorOccured,
fromInBackground.imageError,
fromInBackground);
}
//------------------------------------------------------------------------------
}
The problem is with show()
of modalDialog
in the onCLickListener
. That causes my app to crash. Why? and how do I solve it?