EditInformation 扩展到 fragment 。我在这一行得到错误
loading = ProgressDialog.show(EditInformation.this,"Fetching...","Wait...",false,false); ,第一个参数类型错误。强>
public void RetrieveInformation(final String id)
{
class GetEmployee extends AsyncTask<Void,Void,String> {
ProgressDialog loading;
@Override
protected void onPreExecute() {
super.onPreExecute();
loading = ProgressDialog.show(EditInformation.this,"Fetching...","Wait...",false,false);
}
@Override
protected void onPostExecute(String s) {
super.onPostExecute(s);
loading.dismiss();
showEmployee(s);
}
@Override
protected String doInBackground(Void... params) {
RequestHandler rh = new RequestHandler();
String s = rh.sendGetRequestParam(Config.RETRIEVE_INFORMATION,id);
return s;
}
}
GetEmployee ge = new GetEmployee();
ge.execute();
}
错误
Error124, 62) error: incompatible types: EditInformation cannot be converted to Context
我改成EditInformation.getActivity(),但是报错non-static method
Best Answer-推荐答案 strong>
改变
loading = ProgressDialog.show(EditInformation.this,"Fetching...","Wait...",false,false);
到
loading = ProgressDialog.show(getActivity(),"Fetching...","Wait...",false,false);
由于您已经在 Fragment 上下文中,getActivity() 应该可以解决问题。
关于java - 错误 124, 62) 错误:不兼容的类型:无法将类转换为上下文,我们在Stack Overflow上找到一个类似的问题:
https://stackoverflow.com/questions/34558893/
|