Error :(124, 62) Error: Incompatible type: Unable to convert class to context… here is a solution to the problem.
Error :(124, 62) Error: Incompatible type: Unable to convert class to context
EditInformation extends to fragments. I get error in this line
loading = ProgressDialog.show(EditInformation.this,"Fetching...","Wait...",false,false);
, the first parameter type of the error.
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();
}
Error
Error:(124, 62) error: incompatible types: EditInformation cannot be converted to Context
I changed to EditInformation.getActivity() but got the error non-static method
Solution
Change
loading = ProgressDialog.show(EditInformation.this,"Fetching...","Wait...",false,false);
to
loading = ProgressDialog.show(getActivity(),"Fetching...","Wait...",false,false);
Since you are already in the Fragment context, getActivity()
should solve the
problem.