Refresh
我的简单应用程序设置为在单击按钮时检索 RSS 提要。
单击刷新按钮启动AsyncTask
检索提要。这AsyncTask
是主要活动的子类。
这是我的班级的样子:
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);
}
//------------------------------------------------------------------------------
}
问题show()
在于. modalDialog
_ onCLickListener
这导致我的应用程序崩溃。为什么?我该如何解决?