繁体   English   中英

对于类型InvoiceTemplateGet,方法execute()未定义

[英]The method execute() is undefined for the type InvoiceTemplateGet

我使用AsyncTask从API获取结果。 我有几个上课的作品。 我创建了另一个AsyncTask类,但出现此错误:

The method execute() is undefined for the type InvoiceTemplateGet

在这行上:

InvoiceTemplateGet template = new InvoiceTemplateGet(PaymentMethodActivity.this, invoiceNumber);
template.execute();

有一个类InvoiceTemplateGet:

public class InvoiceTemplateGet {

    public InvoiceTemplateGet(Context context, String invoiceNumber){
        mContext = context;
        this.invoiceNumber = invoiceNumber;
        load_default_settings();
    }


    protected CustomAsyncTaskResult<String> doInBackground(String... arg0) {
        try{
            DefaultHttpClient httpclient = new DefaultHttpClient();
            HttpGet httpget = new HttpGet(url);
            ResponseHandler<String> responseHandler = new BasicResponseHandler();
            String response = httpclient.execute(httpget,responseHandler);
            return new CustomAsyncTaskResult<String>(response);
        }catch (HttpResponseException e){
            return new CustomAsyncTaskResult<String>(new ApiException("Invoice", "Invoice was not found."));
        }catch (Exception e){
            Log.e("Invoice Error", "Error:", e);
            return new CustomAsyncTaskResult<String>(new ApiException("Invoice", e.getMessage()));
        }
    }

    protected void onPostExecute(CustomAsyncTaskResult<String> result) {
        ((PaymentMethodActivity)mContext).getResultFromTemplate(result);
        progressDialog.dismiss();
    }
}

我有另一个与此相同的类,只是url不同。 它在与这一页相同的页面上,在代码的同一部分上执行。 它有效,那么为什么我仍然出现此错误?

我有另一个与此相同的类,只是url不同。 它在与这一页相同的页面上,在代码的同一部分上执行。 它有效,那么为什么我仍然出现此错误?

您的InvoiceTemplateGet没有名为execute()的方法。 查看您的代码,对我来说您忘记了extend AsyncTask 您也可以创建您的execute()方法,以实例化内部AsyncTask并调用instance.execute()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM