views:

402

answers:

3

appdata.items is NSMutableArray object.

source code

-(void)deleteAppDataItemId:(NSInteger)identifier{
    NSLog(@"%@", [appdata.items objectAtIndex:identifier]);
    NSLog(@"%i", identifier);
    [appdata.items removeObjectAtIndex:identifier];
}

log

2009-11-08 21:53:01.683 xxx[14283:207] (
    200,
    "",
    2009-11-08 21:52:53 +0900
)
2009-11-08 21:53:01.684 xxx[14283:207] 0
2009-11-08 21:53:01.685 xxx[14283:207] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[NSCFArray objectAtIndex:]: index (0) beyond bounds (0)'

What caused this error?

A: 

And is there anything unusual about your 'NSCFArray' class?

It's a while since I used objective-c, so I can't remember what it does with NSInteger as an index, compared to 'int', but could this also be an issue?

Ben K
`-objectAtIndex:` takes an `NSUInteger` since Mac OS X 10.5
Georg
A: 

I believe the crash happens in another array. Have you tried using a debugger?

Georg
+3  A: 

Set the debugger to break on objc_exception_throw, then run your program in the debugger. When you hit the exception, look at the stack trace. Some of the frames in the stack will be in Cocoa or CF code; others will be in your code. Switch to the topmost frame that's in your code, and start examining variables. You should find the problem in short order that way.

Peter Hosey