所以,我的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.
我该如何解决?
答案 0 :(得分:3)
ProgressDialog需要一个活动上下文。试试这个:
pDialog = new ProgressDialog(YourActivity.this);
答案 1 :(得分: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();
}
在此构造函数中传递调用类的上下文