1

所以,我有我AsyncTask的如下:

private class AsyncRetriever extends AsyncTask<IotdHandler,Void,IotdHandler>{
        ProgressDialog pDialog;
        @Override
        protected void onPreExecute(){
            pDialog = new ProgressDialog(getApplicationContext());
            pDialog.setMessage(getResources().getString(R.string.toast_msg1));
            pDialog.show();
        }
//------------------------------------------------------------------------------  

这是MainActivity. 但是,LogCat 标记pDialog.show()为错误。
它说,Unable to start activity ComponentInfo.

我该如何解决这个问题?

4

2 回答 2

3

ProgressDialog 需要一个活动上下文。尝试这个:

pDialog = new ProgressDialog(YourActivity.this);
于 2013-07-31T07:54:19.107 回答
1
private class AsyncRetriever extends AsyncTask<IotdHandler,Void,IotdHandler>{
    ProgressDialog pDialog;
Context mcontext;
public AsyncRetriever(Context c){
   mcontext=c
}
    @Override
    protected void onPreExecute(){
        pDialog = new ProgressDialog(mcontext);
        pDialog.setMessage(getResources().getString(R.string.toast_msg1));
        pDialog.show();
    }

在此构造函数中传递调用类的上下文

于 2013-07-31T09:49:25.987 回答