我使用AsyncTask從API獲取結果。我有幾個工作正常的類。我已經創造了另一個的AsyncTask類,但我得到這個錯誤:對於類型InvoiceTemplateGet未定義方法execute()
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 – Blackbelt
哦,我的上帝......你能把它寫成一個答案嗎? – kristyna
看起來像是從某處複製粘貼'InvoiceTemplateGet'類的主體,但忘記了將類AssertTask>添加到類聲明中 –
nikis