Skip navigation
Currently Being Moderated

List Error:invalidIndex when remove an item

Nov 8, 2010 3:49 AM

Hi Guys,


I got the following exception, when i removed an item from spark list. I stepped into to see the index, i looked all right. Somehow, it went the following stack, and the index became an invalid index, which i am not sure where it was from. I found this thread -, but it is not the same problem.



Error: invalidIndex
    at spark.layouts.supportClasses::LinearLayoutVector/remove()[E:\dev\4.x\ frameworks\projects\spark\src\spark\layouts\supportClasses\LinearLayou]
    at spark.layouts::VerticalLayout/elementRemoved()[E:\dev\4.x\frameworks\ projects\spark\src\spark\layouts\]
    at spark.components::DataGroup/[E:\dev\4.x\frameworks\projects\spark\src\spark\components\DataGroup .as:1580]
    at spark.components::DataGroup/removeRendererAt()[E:\dev\4.x\frameworks\ projects\spark\src\spark\components\]
    at spark.components::DataGroup/removeAllItemRenderers()[E:\dev\4.x\frame works\projects\spark\src\spark\components\]
    at spark.components::DataGroup/createItemRenderers()[E:\dev\4.x\framewor ks\projects\spark\src\spark\components\]
    at spark.components::DataGroup/commitProperties()[E:\dev\4.x\frameworks\ projects\spark\src\spark\components\]
    at mx.core::UIComponent/validateProperties()[E:\dev\4.x\frameworks\proje cts\framework\src\mx\core\]
    at mx.managers::LayoutManager/validateProperties()[E:\dev\4.x\frameworks \projects\framework\src\mx\managers\]
    at mx.managers::LayoutManager/doPhasedInstantiation()[E:\dev\4.x\framewo rks\projects\framework\src\mx\managers\]
    at mx.managers::LayoutManager/doPhasedInstantiationCallback()[E:\dev\4.x \frameworks\projects\framework\src\mx\managers\]



Thanks in advance,


  • Currently Being Moderated
    Nov 8, 2010 9:08 AM   in reply to cheng.wei

    Can you please provide a small sample application that demonstrates the error?

    Mark as:
  • Currently Being Moderated
    Nov 14, 2010 11:22 PM   in reply to cheng.wei

    How are you removing the item, do you call myList.dataProvider.removeItemAt(x) ?

    Mark as:
  • Currently Being Moderated
    Jan 3, 2011 12:42 PM   in reply to Shongrunden



    I have exactly the same problem, getting the same error message and stack report (precisely the same).


    All I can say about the error is that it is very random - I can't figure out what changes the situation to produce the error.


    I have a class, extending the spark's TabBar, with a function to close a tab:


    public class VerticalIconTabBar extends TabBar
             public function closeTab(closedTab:int, selectedTab:int):void {
                 if (dataProvider.length == 0) return;
                 if (dataProvider is ViewStack){
                     //remove the entire child from the dataProvider, which also removes it from the ViewStack
                     (dataProvider as ViewStack).removeChildAt(closedTab);
                 //adjust selectedIndex appropriately
                 if (dataProvider.length == 0) {
                     selectedIndex = -1;
                 } else if (closedTab < selectedTab) {
                     selectedIndex = selectedTab - 1;
                 } else if (closedTab == selectedTab) {
                     selectedIndex = (selectedTab == 0 ? 0 : selectedTab - 1);
                 } else {
                     selectedIndex = selectedTab;



    I am showing you the whole  function, though I believe that the '//adjust selectedIndex  appropriately' part is not behind the problem. The problem occurs,  though, only when I am removing the last element from the taskbar (as far as I can tell) and it happens after this function has been called.


    One thing I noticed, but it might be sort of a red herring, is that I can reproduce the error after working a little bit longer (20+ seconds lets say) in the particular Viewstack view - or it's not about time but rather about clicking on different buttons in my UI, I am simply guessing.


    These are the locals of the LinearLayoutVector and its remove(index:uint) function at the time of the error thrown:


    this: pendingInserts = null, pendingRemoves = null, pendingLength = -1, length = 0


    index = 0 (this causes the error as it equals this.length)

    lastIndex = 0

    intervalStart = 0


    I suppose the length shouldn't be 0 or the function shouldn't be called at all - but I cannot affect that.


    I would be very grateful if you could point me towards the direction for solving this, as it causes the whole UI to jam and the only solution is to restart the whole application.


    Thank you,


    Mark as:
  • Currently Being Moderated
    Jan 9, 2011 3:35 PM   in reply to xixixao

    If you set useVirtualLayout="false" on the TabBar do you get other errors?


    Can you create a small, complete sample application that demonstrates this? 

    Mark as:
  • Currently Being Moderated
    Jan 10, 2011 8:03 AM   in reply to Shongrunden

    That's exactly the type of idea I needed - it made me look at the DataGroup (inside of the false stack) and voila - the problem was in a Spark List I am also using inside of the application! (it would probably be enough to read the originial post - well, silly me)


    Now I know precisely when the error happens:

    <s:List labelFunction="formatSelected" dataProvider="{dp.selected}" />


    This is the list, and as you could guess, "dp" is an object, that changes with the controlling of the TabBar.


    1) If I set dp to null and prior to that, didn't change dp.selected from its initial new ArrayCollection(), then the error wasn't thrown.


    2) If I set dp to null, and prior to that, did add some objects to the ArrayCollection, everything was still fine.


    3) But if set dp to null, and prior to that changed the ArrayCollection and as the last step called ArrayCollection.removeAll(), then the error did occur.


    Now, I have a feeling that the problem might be inside of the binding mechanism of MXML (which by the way doesn't work as expected:

    <info:MultipleLinesBox showedArray="{dp.selected}"> -> triggers only with a change to "dp" or assignment to "dp.selected", but not when you add or remove items - as it doest with Spark List's 'dataProvider' - another question of mine )


    Two interesting facts are:

    1) setting useVirtualLayout="false" on the Spark List does solve the problem

    2) if so, in a situation where the error occured previously, now the list "shrinks" to almost 0 height (the border stays, probably)


    I won't be probably using the List at all in the final product (another 'by the way': the fact that I have to go and search for and in the ListSkin.mxml file to change the number of List's required rows properly in my application still seems ridiculous to me - but that's Flex4's skins in all their beauty ) but I am still interested in the whereabouts of this error...

    Mark as:
  • Currently Being Moderated
    Jan 13, 2011 5:42 AM   in reply to cheng.wei

    Hello all,


    I have exactly the same error stack.

    The error was extremely hard to reproduce because I have several asyncronious calls that update the List. But I've catched this error several times but cannot debug it because it is very rare.


    Does anybody know the good workaround?

    Mark as:
  • Currently Being Moderated
    Jan 13, 2011 9:49 AM   in reply to Denis Elkin

    As I stated above:


    1) setting useVirtualLayout="false" on the Spark List does solve the problem

    You might want to try it first (unless you need VirtualLayout to be 'true').

    Mark as:
  • Currently Being Moderated
    Jan 14, 2011 3:19 AM   in reply to xixixao

    Thank you!


    I will try to set useVirtualLayout to false and check if it helps.

    Mark as:
  • Currently Being Moderated
    Jan 21, 2011 3:02 AM   in reply to xixixao

    I performed some tests. Unfortunately I cannot set useVirtualLayout="false" due to perfomance reasons. The application becomes unusable after adding 50+ elements to the List (the ItemRenderer is rather complex).


    The question to Adobe support:

    Have you reproduced the problem?

    Is it true that this is a bug in Flex SDK?

    If it is true, when do you plan to create a bugfix?


    This is a very important issue for me.

    Great thanks in advance for your support!

    Mark as:
  • Currently Being Moderated
    Jan 24, 2011 5:04 PM   in reply to Denis Elkin

    No we haven't reproduced the problem yet.  In order to investigate further we need a sample application that demonstrates the issue.


    If anyone can take their existing project, duplicate it, then strip out as much uneccessary code as possible while still reproducing the bug, then we can investigate further. 


    I'd be happy to help with this "stripping down" process if someone can send me a complete, compilable FXP to start from.

    Mark as:
  • Currently Being Moderated
    Jan 25, 2011 9:36 AM   in reply to Shongrunden

    I'll try to make the sample, but it won't be before the next weekend.

    Mark as:
  • Currently Being Moderated
    Jan 25, 2011 11:35 AM   in reply to xixixao

    I'm having the exact same problem now so I'll be watching this thread. Just discovered it. I see in a question above it is asked if we're removing the item from the dataProvider of the list or the source arrayCollection (I'm doing the latter). Setting useVirtualLayout = "false" doesn't help.

    Mark as:
  • Currently Being Moderated
    Feb 2, 2011 2:11 AM   in reply to xixixao

    I've noticed one more thing. This issue occurs only on last Flash Player (10,1,102,64). On FP version 10.0 the player did not crash on this issue.

    Hope this helps.

    Mark as:
  • Currently Being Moderated
    Jun 17, 2012 4:58 AM   in reply to cheng.wei

    Did you ever get this fixed?


    I'm managing to reproduce it 18 months later....


    Latest Flex SDK and latest Air SDK. Practically the same issue you're having. It occurs for me when I call a removeAll() on the array collection that is bound as the data provider for a spark list.

    Mark as:
  • Currently Being Moderated
    Sep 25, 2012 6:41 AM   in reply to HopkinFrog

    This problem comes from DataGroup trying to DELETE an Array property (Let's hope from a crappy refactoring): 


    // Remove previously "in view" IR from the item=>IR table

    var elt:IVisualElement = indexToRenderer[vrIndex] as IVisualElement;

    delete indexToRenderer[vrIndex];


    It kind of remove the item at vrIndex... But leaves the Array in a terrible state (e.g the length property remains at the current value).


    This is beyond broken, even in the super permissive JS it wouldn't work. By the way, time to move to JS :-P

    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points