0

我有一个 AsyncTask 的问题,当我使用这个功能时,90% 的它崩溃了,我不知道为什么。我能做些什么呢?obs:忽略返回类型

protected Boolean doInBackground(ArrayList<cldetailday>... params){
boolean HaveOpenHour = false;
ArrayList<String> lstHours = new ArrayList<String>();
ArrayList<cldetailday> lstdetail = new ArrayList<cldetailday>();
Time _time = new Time();
_time.hour = 0;
_time.minute = 0;
try {
        lstdetail = params[0];  
         if(lstdetail != null & lstdetail.size() > 0){
             for(int i = 0; i < lstdetail.size(); i++){
                 lstHours.add(lstdetail.get(i).getHora());
                 if(((i+1)%2 == 0)){                             
                     // Fechei um lancamento
                     HaveOpenHour = true;
                     _time.hour += UtilsDate.Instance().TimeDiff(lstHours.get(i-1),lstHours.get(i)).getHour();
                     _time.minute += UtilsDate.Instance().TimeDiff(lstHours.get(i-1),lstHours.get(i)).getMinute();
                 }
                 else{
                     HaveOpenHour = false;
                 }
             }
         }
         // Temos horas em aberto, inserimos a hora atual para fechar esse lancamento
         if(!HaveOpenHour){
             // temos alguem na lista para processar horas
             if(lstHours != null && lstHours.size() > 0){
                  clHour hour = UtilsDate.Instance().getCurrentHour();

                 _time.hour += UtilsDate.Instance().TimeDiff(lstHours.get(lstHours.size() - 1), hour.getStringHour()).getHour();
                 _time.minute += UtilsDate.Instance().TimeDiff(lstHours.get(lstHours.size() - 1), hour.getStringHour()).getMinute();
                 _time.normalize(true);

             }
         }          
    return true;        
} catch (Exception e) {
    // TODO: handle exception
    Log.e("Error doBackground: ", e.getMessage());
    return false;
}

错误:

09-25 20:27:15.576: E/AndroidRuntime(566): FATAL EXCEPTION: AsyncTask #5
09-25 20:27:15.576: E/AndroidRuntime(566): java.lang.RuntimeException: An error occured while executing doInBackground()
09-25 20:27:15.576: E/AndroidRuntime(566):  at android.os.AsyncTask$3.done(AsyncTask.java:200)
09-25 20:27:15.576: E/AndroidRuntime(566):  at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:274)
09-25 20:27:15.576: E/AndroidRuntime(566):  at java.util.concurrent.FutureTask.setException(FutureTask.java:125)
09-25 20:27:15.576: E/AndroidRuntime(566):  at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:308)
09-25 20:27:15.576: E/AndroidRuntime(566):  at java.util.concurrent.FutureTask.run(FutureTask.java:138)
09-25 20:27:15.576: E/AndroidRuntime(566):  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088)
09-25 20:27:15.576: E/AndroidRuntime(566):  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581)
09-25 20:27:15.576: E/AndroidRuntime(566):  at java.lang.Thread.run(Thread.java:1019)
09-25 20:27:15.576: E/AndroidRuntime(566): Caused by: java.lang.NullPointerException: println needs a message
09-25 20:27:15.576: E/AndroidRuntime(566):  at android.util.Log.println_native(Native Method)
09-25 20:27:15.576: E/AndroidRuntime(566):  at android.util.Log.e(Log.java:230)
09-25 20:27:15.576: E/AndroidRuntime(566):  at com.wpa.pontoeletronico.GetTotalHour.doInBackground(GetTotalHour.java:71)
09-25 20:27:15.576: E/AndroidRuntime(566):  at com.wpa.pontoeletronico.GetTotalHour.doInBackground(GetTotalHour.java:1)
09-25 20:27:15.576: E/AndroidRuntime(566):  at android.os.AsyncTask$2.call(AsyncTask.java:185)
09-25 20:27:15.576: E/AndroidRuntime(566):  at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306)
09-25 20:27:15.576: E/AndroidRuntime(566):  ... 4 more
4

2 回答 2

1
   Log.e("Error doBackground: ", e.getMessage());

改成

Log.wtf("Your asyntask TAG","Error doBackground: ",e);

发生这种情况的一个可能原因是 e.getMessage() 不返回任何消息,而在 Log.wtf 方法中,您可以在第三个参数的方法(可以为 null)中传递异常实例。

于 2013-09-25T23:53:00.543 回答
0

它在生产线上失败了

Log.e("Error doBackground: ", e.getMessage());

不是吗?

您的异常e对象没有消息并返回nullon e.getMessage()

于 2013-09-25T23:56:50.113 回答