我在我的应用程序中使用 AsyncTask,但是当它启动时,它就像永远不会结束。当我在doInBackground
应用程序冻结并卡在ThreadPoolExecutor.runWorker(ThreadPoolExecutor$Worker)
.
这是我的代码的结构
class FetchSymbolInfo extends AsyncTask<String, Void, Document> {
private Exception exception = null;
@Override
protected Document doInBackground(String... params)
{
try
{
Document doc = null;
//doc = Jsoup.connect(params[0]).get();//application freezes even if I remove this line
return doc;
}
catch (Exception e)
{
this.exception = e;
return null;
}
}
@Override
protected void onPostExecute(Document result)
{
if(exception != null)
{
AlertDialog alertDialog;
alertDialog = new AlertDialog.Builder(null).create();//////////
alertDialog.setTitle("Error");
alertDialog.setMessage("Could not fetch from internetd\nPlease check your inernet connection and symbol name.");
alertDialog.show();
return;
}
Elements valueElement = result.select("div#qwidget_lastsale");
String valueString = valueElement.toString();
//getting number from string
}
@Override
protected void onPreExecute() {
}
@Override
protected void onCancelled() {
super.onCancelled();
}
@Override
protected void onCancelled(Document result) {
super.onCancelled(result);
}
@Override
protected void onProgressUpdate(Void... values) {
super.onProgressUpdate(values);
}
我正在尝试像这样执行它
String url = "url"; //writing an url
FetchSymbolInfo fetch = new FetchSymbolInfo();
fetch.execute(url);
有任何想法吗?先感谢您!