I'm having problem initialising an NSMutableArray called _entryArray with 2 NSString objects @"00:00:00". I'm getting the following error:
Terminating app due to uncaught exception 'NSRangeException', reason: '* -[__NSArrayM objectAtIndex:]: index 1 beyond bounds for empty array'
When I try to initialise it without any objects in it, I get no errors. What do I do?
Thank you very much
code:
@implementation MainViewController{
@private
int n;
NSMutableArray *_entryArray;
NSMutableArray *_timeSinceLastEntryArray;
NSMutableArray *_timeInterval;
NSMutableArray *_timeInBackup;
NSMutableArray *_timeOutBackup;
BOOL whichButton;
}
-(void)viewWillAppear:(BOOL)animated {
}
- (void)viewDidLoad
{
[super viewDidLoad];
n=0;
_brain = [[Brain alloc] init];
_entryArray = [[NSMutableArray alloc] initWithObjects:@"00:00:00",@"00:00:00",nil];
_timeSinceLastEntryArray = [[NSMutableArray alloc] init];
_timeInBackup = [[NSMutableArray alloc] initWithObjects:(NSNumber *)0, nil];
_timeOutBackup = [[NSMutableArray alloc] initWithObjects:(NSNumber *)0, nil];
_timeInterval = [[NSMutableArray alloc] init];
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]
initWithTarget:self
action:@selector(dismissKeyboard)];
[self.view addGestureRecognizer:tap];
}
_timeInBackup = [[NSMutableArray alloc] initWithObjects:(NSNumber *)0, nil];should be_timeInBackup = [[NSMutableArray alloc] initWithObjects:@0, nil];or in the old syntax_timeInBackup = [[NSMutableArray alloc] initWithObjects:[NSNumber numberWithInt:0], nil];same goes for_timeOutBackup.