NSMutableArrays

Discussion in 'Mac Programming' started by apffal, Mar 3, 2008.

  1. macrumors newbie

    Joined:
    Feb 10, 2008
    #1
    In my application, I want to compare floats in two NSMutableArrays - one sorted and the other unsorted - and get some action accordingly that comparison.
    After each step, I want to remove the first group of floats in the unsorted array and go to next step.
    However, always get a runtime error "index (0) beyond bounds (0)".
    What is wrong ?
    Thanks for help.

    That is my code.

     
  2. macrumors 68040

    iSee

    Joined:
    Oct 25, 2004
    #2
    Your program is trying to to use an invalid index in an array. Specifically, it looks like it is trying to access an object at index 0 on an array that is empty.

    Run your program using the debugger to see exactly what line is causing the problem and trace back the issue from there.
     
  3. thread starter macrumors newbie

    Joined:
    Feb 10, 2008
    #3
    The debugger says that the line is causing the problem is this

    [quoc removeObjectAtIndex:0];
     
  4. thread starter macrumors newbie

    Joined:
    Feb 10, 2008
    #4
    The debugger says that the line is causing the problem is this

    [quoc removeObjectAtIndex:0];
     
  5. macrumors 68040

    iSee

    Joined:
    Oct 25, 2004
    #5
    So you're trying to remove more objects than are in the array.

    One thing you might try is making all the variables that you are using like local variable (i, j, k, num, ordem, quoc, etc.) actual local variables (that is, declare them within the scope of the calc method.

    The value of these variables could be getting changed by other methods. That could account for this problem. There's no way to tell from looking at this fragment, but it's generally a good idea anyway.

    By the way, you can put your code between [code]...[/code] tags to preserve indenting.
     

Share This Page