无法捕获AsyncTask的异常 [英] Can't catch an exception of AsyncTask

查看:87
本文介绍了无法捕获AsyncTask的异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码:

This is my code:

public void onClick(View arg0) {
try{
   new DownloadFilesTask().execute("url3");//url3 is not used in Connect()
        }catch(Exception e){
            e.toString();// I can't catch an exception!
        }
    }
   };//on click;
private class DownloadFilesTask extends AsyncTask<String, Integer, Long&gt; {
    protected Long doInBackground(String... urls) {
     Connect();
     long i = 10;
     return i;
    }

}


目标操作系统是Android 2.2.应用程序崩溃了,我无法捕捉到异常.请帮忙.


Target OS is Android 2.2. Aplication crashing and I can''t catch an exception. Please help.

推荐答案

我认为您想在doInBackground方法中显示某些内容.
UI在另一个线程中运行,然后在您的AsyncTask中运行.
尝试使用onPostExecute方法完成所有UI工作.
I think you want to display something in the doInBackground method.
The UI runs in another thread then your AsyncTask.
Try to do all UI work in the onPostExecute method.


这篇关于无法捕获AsyncTask的异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆