title: App crashes when retrieving data from firebase database
body: <p>I've created a storage reference which stores my images within a folder with a unique UserID (for the logged in user), so when they upload a picture with that storage reference, the image will go into that firestore location, as well as a database reference to that image. It all gets uploaded correctly and appears in my realtime database within a userID as well as the firebase storage. However, when trying to view it in a recycler view, the application crashes, if I just put both storage and database reference as an "uploads" folder at the root of the database and storage, it works fine, but when trying to do it so that the images are taken to a unique UserID folder within the uploads folder, it doesn't work.</p>
  
  <p>The error code I get: <em>java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.Button.setOnClickListener(android.view.View$OnClickListener)' on a null object reference</em></p>
  
  <p>After debugging, error begins after: </p>
  
  <pre><code>mDatabaseRef.addValueEventListener(new ValueEventListener() {
  </code></pre>
  
  <p>in the RecyclerView retrieve file code.</p>
  
  <p>Here shows that when I press upload, the images and database references are taken to the correct location: <a href="https://i.stack.imgur.com/4XTWB.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/4XTWB.jpg" alt="enter image description here"></a></p>
  
  <p><a href="https://i.stack.imgur.com/N7S2q.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/N7S2q.jpg" alt="enter image description here"></a></p>
  
  <p>So the issue here is that it's unable to locate the images when retrieving them, so if someone could give me the correct getReference for this, or even if there's any other error, it will be most welcome.</p>
  
  <p><strong>Upload file task</strong></p>
  
  <pre><code>    if (mImageUri != null) {
          userID = mFirebaseAuth.getCurrentUser().getUid();
          StorageReference fileReference = mStorageRef.child(userID + "/" + System.currentTimeMillis() + "." + getFileExtension(mImageUri));
  
          mUploadTask = fileReference.putFile(mImageUri)
                  .addOnSuccessListener(new OnSuccessListener&lt;UploadTask.TaskSnapshot&gt;() {
                      @Override
                      public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
                          Handler handler = new Handler();
                          handler.postDelayed(new Runnable() {
                              @Override
                              public void run() {
                                  mProgressBar.setProgress(0);
                              }
                          }, 500);
  
                          Toast.makeText(getActivity(), "Upload successful", Toast.LENGTH_SHORT).show();
                          Task&lt;Uri&gt; urlTask = taskSnapshot.getStorage().getDownloadUrl();
                          while (!urlTask.isSuccessful());
                          Uri downloadUrl = urlTask.getResult();
  
                          Upload upload = new Upload(mEditTextFileName.getText().toString().trim(), mEditTextFileTags.getText().toString(),downloadUrl.toString() );
  
                          String uploadId = userID + "/" + mDatabaseRef.push().getKey();
                          mDatabaseRef.child(uploadId).setValue(upload);
  
                      }
                  })
                  .addOnFailureListener(new OnFailureListener() {
                      @Override
                      public void onFailure(@NonNull Exception e) {
                          Toast.makeText(getActivity(), e.getMessage(), Toast.LENGTH_SHORT).show();
                      }
                  })
                  .addOnProgressListener(new OnProgressListener&lt;UploadTask.TaskSnapshot&gt;() {
                      @Override
                      public void onProgress(UploadTask.TaskSnapshot taskSnapshot) {
                          double progress = (100.0 * taskSnapshot.getBytesTransferred() / taskSnapshot.getTotalByteCount());
                          mProgressBar.setProgress((int) progress);
                      }
                  });
      }           
  </code></pre>
  
  <p><strong>RecyclerView retrieve code</strong></p>
  
  <pre><code>    mDatabaseRef = FirebaseDatabase.getInstance().getReference("uploads/");
      mDatabaseRef.addValueEventListener(new ValueEventListener() {
          @Override
          public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
              for (DataSnapshot postSnapshot : dataSnapshot.getChildren()) {
                  Upload upload = postSnapshot.getValue(Upload.class);
                  mUploads.add(upload);
              }
  
              mAdapter = new ImageAdapter(getActivity(), mUploads);
  
              mRecyclerView.setAdapter(mAdapter);
          }
  </code></pre>