11 Replies Latest reply on Jul 12, 2011 2:38 AM by Shailen TJ

    RangeError: Index '-1' specified is out of bounds.

    tuliptaurus

      Hi ,

       

      Whenever i try to deselect a checkbox i get this error


      RangeError: Index '-1' specified is out of bounds

       

                       at mx.collections::ListCollectionView/removeItemAt()

       


      Can anyone guide me in this ?

      Thanks

        • 1. Re: RangeError: Index '-1' specified is out of bounds.
          pauland Level 4

          Do you have an event handler that is calling removeItemAt() somewhere when the checkbox is cleared? That's my suspicion.

          • 2. Re: RangeError: Index '-1' specified is out of bounds.
            BhaskerChari Level 4

            Hi tuliptaurus,

             

            Can you please tell me exactly what action you are performing when you are deselecting a checkbox. I suspect that you are trying to remove an item from a List or ArrayCollection for which the index doesn't exist. It mean you are trying to remove an item at a particular index which doesn't exist.

             

            Can you post sample code reproducing your problem...??

             

            Thanks,

            Bhasker Chari

            • 3. Re: RangeError: Index '-1' specified is out of bounds.
              tuliptaurus Level 1

              yes ! I do have an change event handler that calls Module.removeItemAt(fielditem) when the checkbox is cleared...

               

              What do I do to correct this ?

              • 4. Re: RangeError: Index '-1' specified is out of bounds.
                pauland Level 4

                 

                What do I do to correct this ?

                LOL - fix the code.

                 

                fielditem (should really be  fieldItem) has a value of -1, so you need to know why that is.

                • 5. Re: RangeError: Index '-1' specified is out of bounds.
                  Matt Le Fevre Level 4

                  tuliptaurus wrote:

                   

                  yes ! I do have an change event handler that calls Module.removeItemAt(fielditem) when the checkbox is cleared...

                   

                  What do I do to correct this ?

                   

                  you're feeding it an index value that doesn't exist, post your code

                  • 6. Re: RangeError: Index '-1' specified is out of bounds.
                    Jayagopal Flex Level 1

                    Hi,

                     

                    Check

                    if (fielditem!=-1)

                    {

                          Module.removeItemAt(fielditem)

                    }

                    • 7. Re: RangeError: Index '-1' specified is out of bounds.
                      pauland Level 4

                      Jayagopal Flex wrote:

                       

                      Hi,

                       

                      Check

                      if (fielditem!=-1)

                      {

                            Module.removeItemAt(fielditem)

                      }

                       

                      It's always better to try and understand why the problem occurs first and then if the check is appropriate a better test would be:

                       

                      if (fielditem >=0 )

                       

                      Since all negative values are invalid in this context (as will be a lot of positive ones). fielditem should possibly be a uint (since all negative numbers are invalid for this purpose), which would highlight where it is being set to -1.

                      1 person found this helpful
                      • 8. Re: RangeError: Index '-1' specified is out of bounds.
                        tuliptaurus Level 1

                        yes Bhasker

                         

                        The action:

                         

                        i have got arnd 6 checkboxes for selection. I can select only 2 checkboxes .

                         

                        If i select more that 2 i get a popup saying i cant select more than 2 checkboxes.

                         

                        so this happens in a fieldSelector Componet which has a changeeventhandler function as below

                         

                        private function changeEventHandler(event:Event) : void
                                {
                                  var addbase:base = new base();
                                  if (selected)
                                  {
                                      selected = false ;
                                      fieldItem.isSelected = false;
                                      addbase.removeField(fieldItem);

                         

                                  }else {
                                    
                                      if (addbase != null )
                                      {
                                          if (addbase.isChartSelected() && (addbase.numFieldsSelected() >= 2))
                                          {
                                              selected = false ;
                                              selectItemChk.selected = false;
                                              fieldItem.isSelected = false;
                                              Alert.show(" it can display only two fields");
                                          }

                                            else

                                             {
                                              selected = true ;
                                              fieldItem.isSelected = true;
                                              addbase.addField(fieldItem);
                                             }
                                      }

                                        else

                                             {
                                        
                                             }
                                     
                                            }
                          
                                }

                         

                        in my base component

                         

                          public function removeField(field:Object):void
                                    {
                                        var index:int = selectedFields.getItemIndex(field);
                                        selectedFields.removeItemAt(index);
                                    }

                        • 9. Re: RangeError: Index '-1' specified is out of bounds.
                          BhaskerChari Level 4

                          HI tuliptaurus,

                           

                          I think the problem is within the function below in the first line of code:

                           

                          public function removeField(field:Object):void
                                      {
                                          var index:int = selectedFields.getItemIndex(field);
                                          selectedFields.removeItemAt(index);
                                      }

                           

                          What does your function getItemIndex(field) include...I think the problem is in this function since in this function you are trying to getItemIndex based on the field Object...If there is no exact match in the function this function is returning index = -1 so in your removeField() function you are trying to remove the item at index at -1 which in real doesn't exist so it throws the error.

                           

                          So you first needs to examine the code in getItemIndex() function that it is returning the correctIndex if not then write a check in removeField() function

                           

                          public function removeField(field:Object):void
                                      {
                                          var index:int = selectedFields.getItemIndex(field);

                                         if(index >= 0)
                                         {
                                               selectedFields.removeItemAt(index);

                                         }    
                                      }

                           

                           

                          Try posting the getItemIndex() function...


                          Thanks,

                          Bhasker Chari

                          • 10. Re: RangeError: Index '-1' specified is out of bounds.
                            tuliptaurus Level 1

                            Thanks all of you for giving so much information on how I should correct that ..... Thank you bhasker for explaining the function flow and what I was missing.

                            • 11. Re: RangeError: Index '-1' specified is out of bounds.
                              Shailen TJ Level 1

                              I obtained this error when I loaded a module containing a dataGrid that imports data from an empty table.

                               

                              Based on the information on this page, I fixed my code as described below:

                               

                              I noticed that FB 4.5 automatically created my callResponder with result = "smthg = getSmthResult.lastResult[0] as smthg"

                               

                              I removed the index from the lastResult property and the problem was fixed.

                               

                              I hope this information helps somebody else.

                               

                              Cheers,