错误:(124、62)错误:类型不兼容:类无法转换为上下文 [英] Error:(124, 62) error: incompatible types: Class cannot be converted to Context

查看:91
本文介绍了错误:(124、62)错误:类型不兼容:类无法转换为上下文的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

EditInformation 扩展为片段.我在这一行出现错误

EditInformation extending to fragment. I get error in this line

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(),但出现错误non-static method

I change to EditInformation.getActivity(), but get error non-static method

推荐答案

更改

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

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

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

Since you're already in a Fragment context, getActivity() shall do the trick.

这篇关于错误:(124、62)错误:类型不兼容:类无法转换为上下文的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆