Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
android进度对话框中设置进度时出现空指针异常_Android_Progressdialog - Fatal编程技术网

android进度对话框中设置进度时出现空指针异常

android进度对话框中设置进度时出现空指针异常,android,progressdialog,Android,Progressdialog,为什么我得到这个空指针异常。这是我的密码 在我第一次从doInBackground方法执行publishProgress之后,我在OnProgressUpdate方法处遇到异常 private class ScanVideoTask extends AsyncTask<String, Integer, String> { private AsyncTaskCompleteListener<String> callback; private

为什么我得到这个空指针异常。这是我的密码 在我第一次从doInBackground方法执行publishProgress之后,我在OnProgressUpdate方法处遇到异常

private class ScanVideoTask extends AsyncTask<String, Integer, String> {
        private AsyncTaskCompleteListener<String> callback;
        private Context context;
        private String resultOutput;
        private ProgressDialog mProgressDialog;

        public ScanVideoTask(AsyncTaskCompleteListener<String> cb) {
            this.callback = cb;
        }

        protected String doInBackground(String... args) {
            // Get the URI of the video path & display it for a short period.
            String filename = args[0];

            int i= 0;
            while(i < 1000000)
            {
                i++;
                int progressPercentage = (int)(((float)i/(float)1000000) * (float)100);
                publishProgress(progressPercentage);
            }
            return "ok";

         }

         protected void onProgressUpdate(Integer... progress) {
             mProgressDialog.setProgress(progress[0]);
         }

         protected void onPreExecute() {
             super.onPreExecute();
             showDialog(DIALOG_DOWNLOAD_PROGRESS);
            }

         protected void onPostExecute(String result) {
            System.out.println("on Post execute called" + result);
            dismissDialog(DIALOG_DOWNLOAD_PROGRESS);
            callback.onTaskComplete(result);
         }
     }

我缺少什么?

您的
ScanVideoTask
mProgressDialog
似乎从未初始化过。
您在哪里启动您的
ScanVideoTask

修改onPreExcecute方法,如下所述:

受保护的void onPreExecute()
{
super.onPreExecute();
mProgressDialog=新建进度对话框(此);
showDialog(对话框下载进度);

}
请添加stacktrace。可能是您没有将DIALOG\u DOWNLOAD\u进度传递给OnCreate方法吗?这就解释了为什么它没有被初始化。
 @Override
        protected Dialog onCreateDialog(int id) {
            switch (id) {
            case DIALOG_DOWNLOAD_PROGRESS:
                mProgressDialog = new ProgressDialog(this);
                mProgressDialog.setMessage("Scanning video..");
                mProgressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
                mProgressDialog.setCancelable(true);
                mProgressDialog.show();
                return mProgressDialog;
            default:
                return null;
            }
        }