APP Bird
APP Bird

Reputation: 1381

Set ProgressBar on custom dialog box for Firebase Uploading

I tried to add custom dialog box which includes a progress bar to display current upload process of file to firebase. but it gives me this error. I think there is a problem passing progress to custom dialog box

java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ProgressBar.setProgress(int)' on a null object reference

       uploadTask.addOnProgressListener(new OnProgressListener<UploadTask.TaskSnapshot>() {
                @Override
                public void onProgress(UploadTask.TaskSnapshot taskSnapshot) {
                    double progress = (100.0 * taskSnapshot.getBytesTransferred()) / taskSnapshot.getTotalByteCount();

                int currentprogress = (int) progress;

                    final Dialog dialog = new Dialog(testactivity.this);
                    WindowManager.LayoutParams aaa = new WindowManager.LayoutParams();
                    aaa.copyFrom(psdialog.getWindow().getAttributes());
                    aaa.width = WindowManager.LayoutParams.MATCH_PARENT;
                    aaa.height = WindowManager.LayoutParams.WRAP_CONTENT;

                  dialog.setContentView(R.layout.progresslayout);
                    dialog.setTitle("Custom Dialog");




                   ProgressBar progressbar = (ProgressBar) findViewById(R.id.progressbar);
progressbar.setProgress(currentprogress);

                    psdialog.show();
                    psdialog.getWindow().setAttributes(lp);





                }
            }).addOnPausedListener(new OnPausedListener<UploadTask.TaskSnapshot>() {
                @Override
                public void onPaused(UploadTask.TaskSnapshot taskSnapshot) {
                }
            });

Upvotes: 0

Views: 638

Answers (1)

hadilq
hadilq

Reputation: 1033

You should use

View dialogView = LayoutInflater.from(getContext()).inflate(R.layout.progresslayout, null, false);
dialog.setContentView(dialogView);
ProgressBar progressbar = (ProgressBar) dialogView.findViewById(R.id.progressbar);

instead of

ProgressBar progressbar = (ProgressBar) findViewById(R.id.progressbar);

Upvotes: 3

Related Questions