i am getting start date and end date from user via date pickerview. when user scroll the pickerview in speed then it crashes there and gives me this exception. so whats the solution?
[
NSMutableArray objectAtIndex:]: index 0 beyond bounds for empty array'
*** Call stack at first throw:
(
0 CoreFoundation 0x013fabe9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x0154f5c2 objc_exception_throw + 47
2 CoreFoundation 0x013f06e5 -[__NSArrayM objectAtIndex:] + 261
3 iFeel 0x0001e1b7 -[S7GraphView drawRect:] + 5714
4 UIKit 0x0047d6eb -[UIView(CALayerDelegate) drawLayer:inContext:] + 426
5 QuartzCore 0x01f6f9e9 -[CALayer drawInContext:] + 143
6 QuartzCore 0x01f6f5ef _ZL16backing_callbackP9CGContextPv + 85
7 QuartzCore 0x01f6edea CABackingStoreUpdate + 2246
8 QuartzCore 0x01f6e134 -[CALayer _display] + 1085
9 QuartzCore 0x01f6dbe4 CALayerDisplayIfNeeded + 231
10 QuartzCore 0x01f6038b _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 325
11 QuartzCore 0x01f600d0 _ZN2CA11Transaction6commitEv + 292
12 QuartzCore 0x01f907d5 _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 99
13 CoreFoundation 0x013dbfbb __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 27
14 CoreFoundation 0x013710e7 __CFRunLoopDoObservers + 295
15 CoreFoundation 0x01339bd7 __CFRunLoopRun + 1575
16 CoreFoundation 0x01339240 CFRunLoopRunSpecific + 208
17 CoreFoundation 0x01339161 CFRunLoopRunInMode + 97
18 GraphicsServices 0x019de268 GSEventRunModal + 217
19 GraphicsServices 0x019de32d GSEventRun + 115
20 UIKit 0x0045442e UIApplicationMain + 1160
21 iFeel 0x00002990 main + 102
22 iFeel 0x00002921 start + 53
)
terminate called after throwing an instance of 'NSException'
the method @deepak and @ Grady Player are talking about is this:
-(void)getGraphicalData{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
//[NSThread sleepForTimeInterval:1];
self.friendBL = [[FriendBL alloc] init];
self.result = [self.friendBL getGraphicalData1:txtStartTime.text andTodate:txtEndTime.text];
if ([self.result isKindOfClass:[NSString class]]) {
UIAlertView * friendListAlertView = [[UIAlertView alloc] initWithTitle:@"Friend List" message:(NSString*) self.result delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil];
[friendListAlertView show];
[friendListAlertView release];
}
else {
self.reportList = (NSMutableArray*) self.result;
NSLog(@"%d",[reportList count]);
}
[pool release];
}
after selecting date i click on button to say done and this is the code
-(IBAction)doneBtn{
[dateView setHidden:YES];
NSLog(@"%@",[dateTimePicker date]);
NSLocale *locale = [[[NSLocale alloc] initWithLocaleIdentifier:@"en_US"] autorelease];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init];
[dateFormatter setDateStyle:NSDateFormatterBehaviorDefault];
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"MM/dd/yyyy hh:mm:ss"];
dateFormat.locale = locale;
if (tag) {
txtEndTime.text=[dateFormat stringFromDate:[dateTimePicker date]];
if (![self compareDates]) {
txtStartTime.text=@"";
txtEndTime.text=@"";
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Warning!" message:@"Date is not in valid" delegate:self cancelButtonTitle:@"ok" otherButtonTitles:nil];
[alert show];
[alert release];
}
}
else {
txtStartTime.text=[dateFormat stringFromDate:[dateTimePicker date]];
}
NSLog(@"%@",[dateFormat stringFromDate:[dateTimePicker date]]);
}
but if i pick a the date slowly it do not crashes
Since you are not calling the method by thread you don’t have to use an autorelease pool. Can you try this following code.
This is my last try to help 🙁