0

先生,如果没有互联网连接,我正在尝试处理该消息。但是如果有任何网络连接,当我仍然继续下载时,就会发生空异常错误。起初,它显示网络连接错误的消息,但当我按下是时,弹出异常错误消息。我们在处理这个案子的时候还需要进一步处理什么?

   timer = new Timer();
    boolean isOnline = WebServiceHandler.isOnline(this);
    if (isOnline) {
        startDownloadTask();
     task = new TimerTask() {

            @Override
            public void run() {
                // TODO Auto-generated method stub
                int progress = downloadProgressBar.getProgress();
                notification.contentView.setProgressBar(R.id.pb, downloadProgressBar.getMax(), progress, false);
                nm.notify(notificationID, notification);
            }
        };

        timer.schedule(task, 10, 500);

    } else {
        connectionErrorDialog.show();
        onDestroy();


    }

}    




@Override
public void stopDownloadTask() {
    downloadGoodListTask.cancel(true);
    downloadGoodListTask.setActivityIsRunning(false);
    downloadGoodListTask = null;

}


 protected void onDestroy() {
    super.onDestroy();
    Log.i("Download Activity", "starting to destroy");
    //timer.cancel();


    wheelProgressBar.destroyDrawingCache();
    downloadProgressBar.destroyDrawingCache();
    finishDialog.dismiss();
    connectionErrorDialog.dismiss();

    downloadProgressBar = null; 
    wheelProgressBar = null;
    progressTextView = null;
    downloadingTextView = null;
    finishDialog = null;
    connectionErrorDialog = null;        
    //timer = null;     
    nm.cancel(notificationID);

    nm = null;
    notification = null;
    /*downloadTask.cancel(true);
    downloadTask.activityIsRunning = false;
    downloadTask = null;*/
    stopDownloadTask();
    timer.cancel();        
    System.gc();

    Log.i("Download Activity", "destroyed");
}


@Override
public void stopDownloadTask() {
    downloadGoodListTask.cancel(true);
    downloadGoodListTask.setActivityIsRunning(false);
    downloadGoodListTask = null;

}
4

2 回答 2

2

不要从 UI 线程外部访问 Android UI 工具包。使用 runOnUIThread 方法,向 Handler 发送消息或使用 AsyncTask。

于 2012-07-27T08:49:26.670 回答
0

例外是因为,downloadGoodListTask 为空,存在。要么,您应该初始化为某个值,要么在 stopDownloadTask() 中处理异常。

于 2012-07-27T09:41:45.663 回答