+-
java-错误:(124,62)错误:不兼容的类型:无法将类转换为上下文
EditInformation扩展为片段.我在这行出现错误

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();
    }

错误

 Error:(124, 62) error: incompatible types: EditInformation cannot be converted to Context

我更改为EditInformation.getActivity(),但收到错误非静态方法

最佳答案
更改

loading = ProgressDialog.show(EditInformation.this,"Fetching...","Wait...",false,false);

loading = ProgressDialog.show(getActivity(),"Fetching...","Wait...",false,false);

由于您已经在Fragment上下文中,因此getActivity()应该可以解决问题.

点击查看更多相关文章

转载注明原文:java-错误:(124,62)错误:不兼容的类型:无法将类转换为上下文 - 乐贴网