title: Firebase Remove data from array giving java.lang.IndexOutOfBoundsException: Index: 1, Size: 1
body: <p>I am please to post this here because I have been wasting 2 days in this error. Actually me have to work with firebase and I don't have much command. I am adding data into array like this method</p>
  
  <pre><code> public void addNewNode(String id, String name,String price){
      HashMap&lt;String, String&gt; names = new HashMap&lt;&gt;();
      names.put("menu_extra_item_id", id);
      names.put("menu_extra_item_name",name);
      names.put("menu_extra_item_price",price);
      names.put("menu_extra_item_quantity",inc_dec_tv.getText().toString());
      ExtraItem.add(names);
      mDatabase.child(userId).setValue(new 
      CalculationModel(userId,restaurant_menu_item_id,
              name_,price_,"1","0",ExtraItem));
  }
  </code></pre>
  
  <p>data is adding perfectly but when me need to remove a specific node it gives me a massive trouble. I am trying this code to remove node</p>
  
  <pre><code> public void deleteNewNode(final String id){
      dataArray = new ArrayList&lt;&gt;();
      DatabaseReference query = mDatabase;
      query.addValueEventListener(new ValueEventListener() {
          @Override
          public void onDataChange(DataSnapshot dataSnapshot) {
  
              for (DataSnapshot child : dataSnapshot.getChildren()) {
                  //child is each element in the finished list
  
                  HashMap&lt;String, String&gt; map = (HashMap&lt;String, String&gt;) 
                  child.getValue();
  
                  dataArray.add(map.get("extraItem")) ;
  
                  int sizeArray = dataArray.size();
                  for (int i =0;i&lt;dataArray.size();i++){
  
                      HashMap&lt;String, String&gt; map2 = new HashMap&lt;&gt;();
                      map2.put("value", dataArray.get(i));
                     // String mapVal = String.valueOf(map2);
  
                      try {
                          JSONObject jsonObject = new JSONObject(map2);
                          JSONArray jsonArray = 
                          jsonObject.getJSONArray("value");
  
                          for (int j = 0;j&lt;jsonArray.length();j++){
                              JSONObject allJsonObject = 
                              jsonArray.getJSONObject(j);
  
                              String val1 = 
                              allJsonObject.optString("menu_extra_item_id");
  
                              int sizeBeforRemove =  ExtraItem.size();
  
                              if(val1.equalsIgnoreCase(id)){
  
                                  int some = i;
                                  ExtraItem.remove(i);
  
                                  String extraItemRemaining = 
                                 ExtraItem.toString();
                                int sizeAfterRemove =  ExtraItem.size();
  
                                  mDatabase.child(userId).setValue(new 
                              CalculationModel(userId,restaurant_menu_item_id,
                                          name_,price_,"1","0",ExtraItem));
  
  
                              }
  
                          }
  
                      } catch (JSONException e) {
                          e.printStackTrace();
                      }
  
                  }
  
              }
          }
  
          @Override
          public void onCancelled(DatabaseError databaseError) {
  
          }
      });
  
  }
  </code></pre>
  
  <p><code>ExtraItem</code> is a grobal array initialized but when I call <code>deleteNode</code> method this gives error    </p>
  
  <blockquote>
    <p>java.lang.IndexOutOfBoundsException: Index: 1, Size: 1                                                                               at java.util.ArrayList.remove</p>
  </blockquote>
  
  <p>also here is I am calling both methods.</p>
  
  <pre><code>if (checkBox != null) {
      checkBox.toggle();
      if (checkBox.isChecked()) {
          item.setCheckBoxIsChecked(true);    
          addNewNode(item.getExtra_item_id(),item.getChild_item_name(), item.getChild_item_price());                                
      } else {
  
          item.setCheckBoxIsChecked(false);                       
          deleteNewNode(item.getExtra_item_id());
      }
  }
  </code></pre>