来源AsyncTask.execute未找到() [英] Source not found on AsyncTask.execute()
问题描述
我想用的AsyncTask相处..
什么我的问题是,我是动态生成textviews的表的基础上,过程的输出。但后来我想通,通过使用AsyncTask的我可以更高效way..So做到这一点,我所做的是如下
I am trying to get along with AsyncTask.. what my problem was that i was building a table of textviews dynamically, based on the output of a procedure.. But then i figured that by using asynctask i can do it in a more efficient way..So, what i did is as follows:
private class DisplayReport extends AsyncTask<Void, Void, Boolean>{
protected void onPreExecute(){
//Message -- "Please wait while the Report Loads..."
}
@Override
protected Boolean doInBackground(Void... params) {
//Here i fetch the data from the procedure via a web service
//parse the result of web service and set a bool variable true or false based on whether the dataset fetched is empty or not.
}
protected void onPostExecute(Boolean value){
if(value == true){
"Please try again later!!"
}
else{
runOnUiThread(GenTable);
}
}
private Runnable GenTable = new Runnable(){
public void run(){
try {
displayReport(result); // in this method i build the table.
} catch (Exception e) {
ad.setTitle("Error..");
ad.setMessage(e.toString());
}
}
};
}
以上异步类是我的主类的内部类延伸活动。
这就是我如何执行的AsyncTask ..
the above async class is an inner class in my main class which extends activity. and this is how i am executing the asynctask..
DisplayReport dr = new DisplayReport();
dr.execute();
现在,当我调试,我得到的上dr.execute错误()找不到源..
我试着在网上搜索了很多,但我根本无法找到任何具体。另外,请让我知道如果我的做法是不正确..
这个问题似乎很愚蠢,但我是新来的Android和Java以及任何帮助将是真正伟大的..
now when i debug, i get the "source not found" error on dr.execute()..
i tried searching a lot on the net, but i simply cannot find out anything concrete. Also, please let me know if my approach is incorrect..
this question might seem very silly, but i am new to android and java as well and any help would be really great..
谢谢!
推荐答案
onPostExecute
已经被在UI线程中运行,所以你不应该创建另一个可运行它。只要你的 onPostExecute
是这样的:
onPostExecute
is already being run in the UI thread, so you should not create another runnable for it. Just make your onPostExecute
like this:
protected void onPostExecute(Boolean value){
if(value == true){
String message = "Please try again later!!";
// Do something here with your message
}
else{
displayReport(result);
}
}
这篇关于来源AsyncTask.execute未找到()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!