【发布时间】:2015-04-22 19:57:38
【问题描述】:
我使用 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 不同。它像这个页面一样在同一页面上执行,在同一部分代码上。它有效,为什么我仍然收到此错误?
【问题讨论】:
-
可能其他类是直接扩展AsyncTask
-
天哪...你能把它写成答案吗?
-
看起来您从某处复制粘贴了
InvoiceTemplateGet类的主体,但您忘记将extends AsyncTask<String, Void, CustomAsyncTaskResult<String>>添加到类声明中
标签: android android-asynctask execution