我有一个 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