title: How to upload multiple images to firebase in android?
body: <p>I know this question has been asked here and answered but for some reasons, provided solutions are not working for me.</p>
  
  <p>So here is how I'm trying to do this. I have two buttons in my layout one to open gallery and other to upload the images.</p>
  
  <p><strong>Defined members</strong></p>
  
  <pre><code>int SELECT_PICTURES = 1;
  
  ArrayList&lt;Uri&gt; mArrayUri = new ArrayList&lt;Uri&gt;();
  Uri imageUri;
  int up = 0;
  int k =0;
  </code></pre>
  
  <p><strong>Gallery button code</strong></p>
  
  <pre><code>Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
      intent.setType("image/*");
      intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
      startActivityForResult(Intent.createChooser(intent, "Select Picture"), SELECT_PICTURES);
  </code></pre>
  
  <p><strong>On Activity result code</strong></p>
  
  <pre><code>@Override
  public void onActivityResult(int requestCode, int resultCode, Intent data) {
      super.onActivityResult(requestCode, resultCode, data);
      if(requestCode == SELECT_PICTURES) {
          if (resultCode == MainActivity.RESULT_OK) {
              if (data.getClipData() != null) {
                  int count = data.getClipData().getItemCount();
                  Log.i("count", String.valueOf(count));
                  int currentItem = 0;
                  while (currentItem &lt; count) {
                      imageUri = data.getClipData().getItemAt(currentItem).getUri();
  
  
                      Log.i("uri", imageUri.toString());
                      mArrayUri.add(imageUri);
                      currentItem = currentItem + 1;
                  }
                  Log.i("listsize", String.valueOf(mArrayUri.size()));
              } else if (data.getData() != null) {
                  String imagePath = data.getData().getPath();
  
              }
          }
      }
  }
  </code></pre>
  
  <p><strong>Upload button code</strong></p>
  
  <pre><code>  StorageReference filepath = FirebaseStorage.getInstance().getReference().child("gpic");
  
  
      while (up &lt; mArrayUri.size()){
  
          // error is pointing to this line, line 82
          filepath.child(mArrayUri.get(k).getLastPathSegment()).putFile(mArrayUri.get(k)).addOnSuccessListener(new OnSuccessListener&lt;UploadTask.TaskSnapshot&gt;() {
              @Override
              public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
                  Uri downloadURL = taskSnapshot.getDownloadUrl();
                  Toast.makeText(TestingActivity.this, downloadURL.toString(), Toast.LENGTH_SHORT).show();
                  up++;
                  k++;
              }
          });
      }
  }
  </code></pre>
  
  <p>The above code uploads one image and then crashes with the following error</p>
  
  <pre><code>01-24 12:37:37.416 8336-8336/com.codenemesis.uploading E/AndroidRuntime: FATAL EXCEPTION: main
                                                                     Process: com.codenemesis.uploading, PID: 8336
                                                                     java.lang.IllegalStateException: Could not execute method for android:onClick
                                                                         at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:293)
                                                                         at android.view.View.performClick(View.java:5610)
                                                                         at android.view.View$PerformClick.run(View.java:22265)
                                                                         at android.os.Handler.handleCallback(Handler.java:751)
                                                                         at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                         at android.os.Looper.loop(Looper.java:154)
                                                                         at android.app.ActivityThread.main(ActivityThread.java:6077)
                                                                         at java.lang.reflect.Method.invoke(Native Method)
                                                                         at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
                                                                         at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)
                                                                      Caused by: java.lang.reflect.InvocationTargetException
                                                                         at java.lang.reflect.Method.invoke(Native Method)
                                                                         at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:288)
                                                                         at android.view.View.performClick(View.java:5610) 
                                                                         at android.view.View$PerformClick.run(View.java:22265) 
                                                                         at android.os.Handler.handleCallback(Handler.java:751) 
                                                                         at android.os.Handler.dispatchMessage(Handler.java:95) 
                                                                         at android.os.Looper.loop(Looper.java:154) 
                                                                         at android.app.ActivityThread.main(ActivityThread.java:6077) 
                                                                         at java.lang.reflect.Method.invoke(Native Method) 
                                                                         at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866) 
                                                                         at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756) 
                                                                      Caused by: java.util.concurrent.RejectedExecutionException: Task com.google.firebase.storage.zzs@c59b7fe rejected from java.util.concurrent.ThreadPoolExecutor@4b6eb5f[Running, pool size = 2, active threads = 2, queued tasks = 128, completed tasks = 0]
                                                                         at java.util.concurrent.ThreadPoolExecutor$AbortPolicy.rejectedExecution(ThreadPoolExecutor.java:2049)
                                                                         at java.util.concurrent.ThreadPoolExecutor.reject(ThreadPoolExecutor.java:814)
                                                                         at java.util.concurrent.ThreadPoolExecutor.execute(ThreadPoolExecutor.java:1360)
                                                                         at com.google.firebase.storage.zzu.zzt(Unknown Source)
                                                                         at com.google.firebase.storage.UploadTask.schedule(Unknown Source)
                                                                         at com.google.firebase.storage.StorageTask.zzcls(Unknown Source)
                                                                         at com.google.firebase.storage.StorageReference.putFile(Unknown Source)
                                                                         at **com.codenemesis.uploading.TestingActivity.up(TestingActivity.java:82)**
                                                                         at java.lang.reflect.Method.invoke(Native Method) 
                                                                         at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:288) 
                                                                         at android.view.View.performClick(View.java:5610) 
                                                                         at android.view.View$PerformClick.run(View.java:22265) 
                                                                         at android.os.Handler.handleCallback(Handler.java:751) 
                                                                         at android.os.Handler.dispatchMessage(Handler.java:95) 
                                                                         at android.os.Looper.loop(Looper.java:154) 
                                                                         at android.app.ActivityThread.main(ActivityThread.java:6077) 
                                                                         at java.lang.reflect.Method.invoke(Native Method) 
                                                                         at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866) 
                                                                         at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756) 
  </code></pre>