getting exception "index 0 beyond bounds for empty array"? - iphone

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.
-(void)getGraphicalData{
self.friendBL = [[[FriendBL alloc] init] autorelease];
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]);
}
}
This is my last try to help :-(

You have an array without any objects in it and you're attempting to access the first object. If you show us code we can be more specific.

In the above function you are not releasing the object FriendBL. How are you storing your property? Retain or assign or copy ?
Might be the problem with autorelease pool. Is the function called on a main thread ?
If you can give us more insight it might be useful.

Related

App Crash: NSInvalidArgumentException

[__NSArrayM relatedObjectDidChange]: unrecognized selector sent to instance
error Class: NSInvalidArgumentException
the crash report stackTrace:
0 CoreFoundation 0x33d153e7 <redacted> + 162
1 libobjc.A.dylib 0x3ba06963 objc_exception_throw + 30
2 CoreFoundation 0x33d18f31 <redacted> + 0
3 CoreFoundation 0x33d1764d <redacted> + 392
4 CoreFoundation 0x33c6f208 _CF_forwarding_prep_0 + 24
5 EventKit 0x3440af03 <redacted> + 30
6 EventKit 0x34410225 <redacted> + 396
7 EventKit 0x34410095 <redacted> + 28
8 EventKit 0x3440d3fd <redacted> + 396
9 Calendar 0x000f10a5 -[createNewEventView editEvent:] + 1696
10 UIKit 0x35c0f087 <redacted> + 70
11 UIKit 0x35c0f111 <redacted> + 120
12 UIKit 0x35c0f087 <redacted> + 70
13 UIKit 0x35c0f03b <redacted> + 30
14 UIKit 0x35c0f015 <redacted> + 44
15 UIKit 0x35c0e8cb <redacted> + 502
16 UIKit 0x35c0edb9 <redacted> + 488
17 UIKit 0x35b375f9 <redacted> + 524
18 UIKit 0x35b248e1 <redacted> + 380
19 UIKit 0x35b241ef <redacted> + 6198
20 GraphicsServices 0x3783b5f7 <redacted> + 590
21 GraphicsServices 0x3783b227 <redacted> + 34
22 CoreFoundation 0x33cea3e7 <redacted> + 34
23 CoreFoundation 0x33cea38b <redacted> + 138
24 CoreFoundation 0x33ce920f <redacted> + 1382
25 CoreFoundation 0x33c5c23d CFRunLoopRunSpecific + 356
26 CoreFoundation 0x33c5c0c9 CFRunLoopRunInMode + 104
27 GraphicsServices 0x3783a33b GSEventRunModal + 74
28 UIKit 0x35b782b9 UIApplicationMain + 1120
29 Calendar 0x000a9bbf main + 66
30 Calendar 0x0003a600 start + 40
What does such error means, and what is the possibilities for such error?
My implementation of editEvent method:
-(void) editEvent:(EKSpan )span
{
EKEvent * newEditingEvent = self.EventToEdit;
CalendarAppDataObject* theDataObject = [self theAppDataObject];
if(eventCalendar != nil && theDataObject.selectedCalendarsForDisplayData != nil){
NSArray *arrayDataUnarchiver =(NSArray *) [NSKeyedUnarchiver unarchiveObjectWithData:theDataObject.selectedCalendarsForDisplayData];
NSMutableSet * uniqueId = [[NSMutableSet alloc ] initWithArray:arrayDataUnarchiver];
[uniqueId addObject:eventCalendar.calendarIdentifier];
NSArray * selectedCal = [uniqueId allObjects];
NSData *arrayDataArchiver = [NSKeyedArchiver archivedDataWithRootObject:selectedCal];
theDataObject.selectedCalendarsForDisplayData = arrayDataArchiver;
//save selected to database
NSError *error;
self.managedObjectContext = theDataObject.managedObjectContext;
NSManagedObjectContext *context = [self managedObjectContext];
// **** log objects currently in database ****
// create fetch object, this objects fetch's the objects out of the database
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:#"Settings" inManagedObjectContext:context];
[fetchRequest setEntity:entity];
NSArray *fetchedObjects= [context executeFetchRequest:fetchRequest error:&error] ;
for (NSManagedObject *info in fetchedObjects)
{
[info setValue:arrayDataArchiver forKey:#"selectedCalendarsForDisplayData"] ;
}
//this is for comitting changes to core data
[context save:&error];
[fetchRequest release];
[uniqueId release];
}
NSString * eventNotesString = #"";
if(self.eventNotes != nil)
{
eventNotesString = self.eventNotes;
}
newEditingEvent.notes = [EventsDataUtil generateEventsNoteForSavingColor:eventNotesString colorToSave:self.eventBackColor];
if(self.eventRecurrenceRule != nil)
{
NSArray * RecRulesArray = [[[NSArray alloc ] initWithObjects:self.eventRecurrenceRule, nil]autorelease];
if(theDataObject.isRepeatChanged)
{
[newEditingEvent setRecurrenceRules:RecRulesArray];
}
}else
{
[newEditingEvent setRecurrenceRules:nil];
}
if([[ self.eventTitle stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]] isEqualToString:#""])
{
self.eventTitle = #"New Event";
}
newEditingEvent.title = self.eventTitle;
if(isLocationPhoneNumber)
{
NSString * PhoneLocationString = #"tel:";
PhoneLocationString = [PhoneLocationString stringByAppendingFormat:#"%#", [self.contactPhoneNumber stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]];
newEditingEvent.location = PhoneLocationString;
}
else
{
newEditingEvent.location = self.eventLocation;
}
newEditingEvent.startDate = self.eventStartDate;
newEditingEvent.endDate =self.eventEndDate;
newEditingEvent.allDay = self.eventAllDay;
newEditingEvent.calendar = self.eventCalendar;
newEditingEvent.URL = self.eventURL;
// repeat and alert
NSArray * Alarms = nil;
if(self.eventAlert !=nil)
{
if(self.eventSecondAlert !=nil)
{
Alarms = [[[NSArray alloc] initWithObjects:self.eventAlert,self.eventSecondAlert, nil]autorelease];
}
else {
Alarms = [[[NSArray alloc] initWithObjects:self.eventAlert, nil]autorelease];
}
}
newEditingEvent.alarms = Alarms;
NSError *err;
[newEditingEvent setCalendar:self.eventCalendar];
[sharedEventStore saveEvent:newEditingEvent span:span commit:YES error:&err];
theDataObject.needUpdate = YES;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
[[NSNotificationCenter defaultCenter] postNotificationName:#"dismissEventDetails" object:nil];
}
else{
[self dismissViewControllerAnimated:YES completion:NULL];
}
}
The error report tells you everything you need to know:
[__NSArrayM relatedObjectDidChange]: unrecognized selector sent to instance
Which means that the NSArray class does not have a method called relatedObjectDidChange, so your code obviously calls this somewhere:
[someArray relatedObjectDidChange];
Without seeing your code, I cannot provide more help. I'd like to see this method:
[createNewEventView editEvent:]
and the definition of that class
The method relatedObjectDidChange is sent to an object of class NSArray which the class does not respond to. Did you mix up an NSMutableArray with an NSArray somewhere?
Or is relatedObjectDidChange a method that you did implement yourself on one of your objects? In that case you probably assigned an NSArray to a variable of which you expect to be of your very own class.

objective c - getting null values

I have been stuck on this for some time now but whats happening is that when the request comes back from mysql there is a null value but how do i check that a null value has hit my condition so that i dont store this value in the array. The code is below
The error i keep getting is -[NSNull isEqualToString:]: unrecognized and im trying to bind the array inside a tableview
- (void)viewDidLoad {
JobAddSiteAppDelegate *ja = (JobAddSiteAppDelegate *)[[UIApplication sharedApplication] delegate];
tempArray = [[NSMutableArray alloc] init];
NSString *strURL = [NSString stringWithFormat:#"http://www.bestitjobs.co.uk/appresults3.php", ""];
NSData *nsData = [NSData dataWithContentsOfURL:[NSURL URLWithString: strURL]];
//NSLog(#"JSON: %#", nsData);
//NSString *strResult = [[[NSString alloc] initWithData:nsData encoding:NSUTF8StringEncoding] autorelease];
//NSLog(#"Result: %#",strResult);
//NSError *e = nil;
JSONDecoder* decoder = [[JSONDecoder alloc] init];
NSDictionary* listDictionary = [nsData objectFromJSONData];
NSArray* people =[listDictionary objectForKey:#"jobs"];
for (NSDictionary *person in people) {
NSLog(#"people %#",people);
if([person objectForKey:#"position"] != [NSNull class])
{
NSString *position = [person objectForKey:#"position"];
NSLog(#"position %#",position);
[tempArray addObject: position];
}
}
self.listData = tempArray;
[tempArray release];
[listData release];
[super viewDidLoad];
}
Error
2012-12-06 12:22:11.314 JobAddSite[7718:207] position Senior Network and Systems Consultant
2012-12-06 12:22:11.316 JobAddSite[7718:207] position SAP Business One / SAP B1 Consultant London
2012-12-06 12:22:11.317 JobAddSite[7718:207] position Business Development Manager - Market Leading IT Company
2012-12-06 12:22:11.318 JobAddSite[7718:207] -[NSNull isEqualToString:]: unrecognized selector sent to instance 0xe565e8
2012-12-06 12:22:11.321 JobAddSite[7718:207] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSNull isEqualToString:]: unrecognized selector sent to instance 0xe565e8'
* Call stack at first throw:
(
0 CoreFoundation 0x00de95a9 exceptionPreprocess + 185
1 libobjc.A.dylib 0x00f3d313 objc_exception_throw + 44
2 CoreFoundation 0x00deb0bb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
3 CoreFoundation 0x00d5a966 __forwarding + 966
4 CoreFoundation 0x00d5a522 _CF_forwarding_prep_0 + 50
5 JobAddSite 0x000024cd -[ResultViewController viewDidLoad] + 604
6 UIKit 0x00389089 -[UIViewController view] + 179
7 UIKit 0x0038aa3d -[UIViewController viewControllerForRotation] + 63
8 UIKit 0x00386988 -[UIViewController _visibleView] + 90
9 UIKit 0x0062893c -[UIClientRotationContext initWithClient:toOrientation:duration:andWindow:] + 354
10 UIKit 0x0030081e -[UIWindow _setRotatableClient:toOrientation:updateStatusBar:duration:force:] + 954
11 UIKit 0x00588619 -[UIWindowController transition:fromViewController:toViewController:target:didEndSelector:] + 1381
12 UIKit 0x0038d65d -[UIViewController presentModalViewController:withTransition:] + 3478
13 JobAddSite 0x0000213f -[JobAddSiteViewController search] + 270
14 UIKit 0x002d94fd -[UIApplication sendAction:to:from:forEvent:] + 119
15 UIKit 0x00369799 -[UIControl sendAction:to:forEvent:] + 67
16 UIKit 0x0036bc2b -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 527
17 UIKit 0x0036a7d8 -[UIControl touchesEnded:withEvent:] + 458
18 UIKit 0x002fdded -[UIWindow _sendTouchesForEvent:] + 567
19 UIKit 0x002dec37 -[UIApplication sendEvent:] + 447
20 UIKit 0x002e3f2e _UIApplicationHandleEvent + 7576
21 GraphicsServices 0x01741992 PurpleEventCallback + 1550
22 CoreFoundation 0x00dca944 CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION + 52
23 CoreFoundation 0x00d2acf7 __CFRunLoopDoSource1 + 215
24 CoreFoundation 0x00d27f83 __CFRunLoopRun + 979
25 CoreFoundation 0x00d27840 CFRunLoopRunSpecific + 208
26 CoreFoundation 0x00d27761 CFRunLoopRunInMode + 97
27 GraphicsServices 0x017401c4 GSEventRunModal + 217
28 GraphicsServices 0x01740289 GSEventRun + 115
29 UIKit 0x002e7c93 UIApplicationMain + 1160
30 JobAddSite 0x00001dec main + 102
31 JobAddSite 0x00001d7d start + 53
)
terminate called after throwing an instance of 'NSException'
Just try this one:
if ([person objectForKey:#"position"]) {..}
This one is the same but maybe more readable:
if ([person objectForKey:#"position"] != nil) {..}
Hi Use the following code.
It is working Well.
Download Supporting Files
NSMutableArray *empArray = [[NSMutableArray alloc] init];
SBJSON *parser = [[SBJSON alloc] init];
NSURLRequest *request1 = [NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:#"http://www.bestitjobs.co.uk/appresults3.php"]]];
NSLog(#"GGGG:%#",request1);
NSData *response1 = [NSURLConnection sendSynchronousRequest:request1 returningResponse:nil error:nil];
NSString *json_string = [[NSString alloc] initWithData:response1 encoding:NSUTF8StringEncoding];
NSDictionary *statuses = [parser objectWithString:json_string error:nil];
NSLog(#"List Dictionary:%#",statuses);
NSArray* people =[statuses objectForKey:#"jobs"];
for(NSDictionary *test in people)
{
[empArray addObject:[test valueForKey:#"position"]];
}
NSLog(#"EMP ARRAY CATEGORY:%#",empArray);
Note: Before you Use SBJSon supporting files and import JSON.h
And check your console.
Check condition like this and add value to Array
for (NSDictionary *person in people) {
NSLog(#"people %#",people);
NSString *position = [person objectForKey:#"position"];
if(position) {
[tempArray addObject: position];
}
}

Abort on iPhone simulator

I am receiving an SIGABRT error on the last line of this code loginButton.enabled = YES;. It was working this morning and now this error comes up.
-(IBAction)login:(id)sender
{
UIButton *loginButton = (UIButton *)sender;
loginButton.enabled = NO;
NSString *filePath = [self dataFilePath];
if([[NSFileManager defaultManager] fileExistsAtPath:filePath])
{
NSArray *array = [[NSArray alloc] initWithContentsOfFile:filePath];
NSString *nameString = [[NSString alloc] init];
NSString *contactIdString = [[NSString alloc] init];
NSString *genderString = [[NSString alloc] init];
NSString *contactTypeString = [[NSString alloc] init];
nameString = [array objectAtIndex:0];
contactIdString = [array objectAtIndex:1];
genderString = [array objectAtIndex:2];
contactTypeString = [array objectAtIndex:3];
self.name = nameString;
self.contactId = contactIdString;
self.gender = genderString;
self.contactType = contactTypeString;
[self.userArray removeAllObjects];
[self performSelectorInBackground:#selector(sendData) withObject:nil];
[nameString release];
[contactIdString release];
[genderString release];
[contactTypeString release];
UIBarButtonItem *logoutButton = [[UIBarButtonItem alloc] initWithTitle:#"Logout" style:UIBarButtonItemStylePlain target:self action:#selector(logout:)];
//[logoutButton setTitle:#"Logout"];
[[self navigationItem] setRightBarButtonItem:logoutButton];
[logoutButton release];
}
else
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"New User" message:#"It seems you have not used FaceDirectory before, please go to My Details and fill out the information then click save." delegate:self cancelButtonTitle:#"Ok" otherButtonTitles:nil];
[alert show];
[alert release];
}
loginButton.enabled = YES;
}
Here is the error dump.
2011-08-12 11:41:56.700 FaceConnect[1651:207] Reachability Flag Status: -R ------- networkStatusForFlags
2011-08-12 11:41:59.247 FaceConnect[1651:207] selected first row
2011-08-12 11:42:02.344 FaceConnect[1651:6b07] *** __NSAutoreleaseNoPool(): Object 0x7a0cf10 of class NSConcreteMutableData autoreleased with no pool in place - just leaking
2011-08-12 11:42:02.344 FaceConnect[1651:207] -[__NSCFData setEnabled:]: unrecognized selector sent to instance 0x6f4b820
2011-08-12 11:42:02.344 FaceConnect[1651:6b07] *** __NSAutoreleaseNoPool(): Object 0x7a108b0 of class NSConcreteMutableData autoreleased with no pool in place - just leaking
2011-08-12 11:42:02.344 FaceConnect[1651:6b07] *** __NSAutoreleaseNoPool(): Object 0x7e06e70 of class NSConcreteMutableData autoreleased with no pool in place - just leaking
2011-08-12 11:42:02.344 FaceConnect[1651:6b07] *** __NSAutoreleaseNoPool(): Object 0x7e06220 of class NSConcreteMutableData autoreleased with no pool in place - just leaking
2011-08-12 11:42:02.345 FaceConnect[1651:6b07] *** __NSAutoreleaseNoPool(): Object 0x7e06ca0 of class NSConcreteMutableData autoreleased with no pool in place - just leaking
2011-08-12 11:42:02.345 FaceConnect[1651:6b07] *** __NSAutoreleaseNoPool(): Object 0x7e068c0 of class NSURL autoreleased with no pool in place - just leaking
2011-08-12 11:42:02.345 FaceConnect[1651:6b07] *** __NSAutoreleaseNoPool(): Object 0x7e061c0 of class NSMutableURLRequest autoreleased with no pool in place - just leaking
2011-08-12 11:42:02.345 FaceConnect[1651:6b07] *** __NSAutoreleaseNoPool(): Object 0x7e069e0 of class NSCFString autoreleased with no pool in place - just leaking
2011-08-12 11:42:02.345 FaceConnect[1651:6b07] *** __NSAutoreleaseNoPool(): Object 0x7e06b30 of class NSCFString autoreleased with no pool in place - just leaking
2011-08-12 11:42:02.345 FaceConnect[1651:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFData setEnabled:]: unrecognized selector sent to instance 0x6f4b820' *** Call stack at first throw: (
0 CoreFoundation 0x0249d919 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x025eb5de objc_exception_throw + 47
2 CoreFoundation 0x0249f42b -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
3 CoreFoundation 0x0240f116 ___forwarding___ + 966
4 CoreFoundation 0x0240ecd2_CF_forwarding_prep_0 + 50
5 FaceConnect 0x0000a7ea -[HubViewController login:] + 1802
6 UIKit 0x00123e14 -[UIApplication sendAction:to:from:forEvent:] + 119
7 UIKit 0x0032b14b-[UIBarButtonItem(UIInternal) _sendAction:withEvent:] + 156
8 UIKit 0x00123e14 -[UIApplication sendAction:to:from:forEvent:] + 119
9 UIKit 0x001ad6c8 -[UIControlsendAction:to:forEvent:] + 67
10 UIKit 0x001afb4a -[UIControl(Internal) _sendActionsForEvents:withEvent:] +527
11 UIKit 0x001ae6f7 -[UIControltouchesEnded:withEvent:] + 458
12 UIKit 0x001472ff -[UIWindow _sendTouchesForEvent:] + 567
13 UIKit 0x001291ec -[UIApplication sendEvent:] + 447
14 UIKit 0x0012dac4 _UIApplicationHandleEvent + 7495
15 GraphicsServices 0x02924afa PurpleEventCallback + 1578
16 CoreFoundation 0x0247edc4 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__+ 52
17 CoreFoundation 0x023df737__CFRunLoopDoSource1 + 215
18 CoreFoundation 0x023dc9c3 __CFRunLoopRun + 979
19 CoreFoundation 0x023dc280 CFRunLoopRunSpecific + 208
20 CoreFoundation 0x023dc1a1 CFRunLoopRunInMode + 97
21 GraphicsServices 0x029232c8 GSEventRunModal + 217
22 GraphicsServices 0x0292338d GSEventRun + 115
23 UIKit 0x00131b58 UIApplicationMain + 1160
24 FaceConnect 0x00001ac9 main + 121
25 FaceConnect 0x00001a45 start + 53
26 ??? 0x00000001 0x0 + 1 )
2011-08-12 11:42:02.346 FaceConnect[1651:6b07] *** __NSAutoreleaseNoPool(): Object 0x7e06a40 of class NSCFString autoreleased with no pool in place - just leaking
2011-08-12 11:42:02.346 FaceConnect[1651:6b07] *** __NSAutoreleaseNoPool(): Object 0x6f4c0c0 of class NSCFString autoreleased with no pool in place - just leaking terminate called after throwing an instance of 'NSException' Current language: auto; currently objective-c
I have just checked it on my iPhone, and the application does not crash. It only happens on the simulator.
-(IBAction)login:(id)sender {
[(UIButton*) sender setEnabled:NO];
if([[NSFileManager defaultManager] fileExistsAtPath:filePath]) {
NSArray *array = [[NSArray alloc] initWithContentsOfFile:filePath];
NSString* name = [array objectAtIndex:0];
NSString* contactId = [array objectAtIndex:1]; // depends if it is an integer then use int
NSString* gender = [array objectAtIndex:2];
NSString* contactType = [array objectAtIndex:3];
//[self.userArray removeAllObjects]; // what is your user array and why you are removing all the objects
// i could not find where you are setting the value for userArray
[self.userArray arrayWithObjects:self.name, self.contactId, self.gender,self.contactType, nil];
[self performSelectorInBackground:#selector(sendData) withObject:nil];
/*if (loginButton.selected == NO) {
// Represents user needs to login. Code for login user.
}else
{
[loginButton setTitle:#"Logout"];
}
// toggle the login/logout states.
loginButton.selected = !loginButton.selected;*/
UIBarButtonItem *logoutButton = [[UIBarButtonItem alloc] initWithTitle:#"Logout" style:UIBarButtonItemStylePlain target:self action:#selector(logout:)];
//[logoutButton setTitle:#"Logout"];
[[self navigationItem] setRightBarButtonItem:logoutButton];
[logoutButton release];
}
else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"New User" message:#"It seems you have not used FaceDirectory before, please go to My Details and fill out the information then click save." delegate:self cancelButtonTitle:#"Ok" otherButtonTitles:nil];
[alert show];
[alert release];
}
[(UIButton*) sender setEnabled:YES];
}
i could not find where you are setting the value for userArray and so i thought i think you are binding the info to userArray and sending
-(id)sendData{
//Do whatever you want to do with userArray
}
-(void)viewDidUnLoad{
self.userarray = nil;
[super viewDidlUnload];
}
-(void)dealloc{
[userArray release];
[super dealloc];
}
You create an empty strings with alloc/init, and then you change them to value returned by objectAtIndex:. This causes the pointer to point to an autoreleased value. After you release your strings, the application will crash because retain count will become less than zero.
I guess the error is propagating from FaceConnect. Please check, it's showing a lot of leaks and warnings.

Crash With WebView in iPhone

I get following crash when I open a URL consecutively for 3 to 4 times in my app inside a webView.
Exception Type: EXC_BAD_ACCESS (SIGBUS)
Exception Codes: EXC_ARM_DA_ALIGN at 0x0062006f
Crashed Thread: 0
Thread 0 Crashed:
0 libSystem.B.dylib 0x0000576c OSAtomicCompareAndSwap32 + 0
1 libobjc.A.dylib 0x000066ce changeInfo(class_t*, unsigned int, unsigned int) + 22
2 libobjc.A.dylib 0x00008412 realizeClass(class_t*) + 38
3 libobjc.A.dylib 0x0000862c prepareForMethodLookup + 44
4 libobjc.A.dylib 0x0000538a lookUpMethod + 34
5 libobjc.A.dylib 0x00002b82 _class_lookupMethodAndLoadCache + 6
6 libobjc.A.dylib 0x000028b8 objc_msgSend_uncached + 20
7 UIKit 0x001d68c2 -[UIWebView webView:didFinishLoadForFrame:] + 214
8 UIKit 0x001d5e0c -[UIWebViewWebViewDelegate webView:didFinishLoadForFrame:] + 16
9 CoreFoundation 0x0009f06c __invoking___ + 60
10 CoreFoundation 0x00032706 -[NSInvocation invoke] + 102
11 WebCore 0x00044d42 SendMessage(NSInvocation*) + 10
12 WebCore 0x0005846e HandleDelegateSource(void*) + 62
13 CoreFoundation 0x00071a86 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 6
14 CoreFoundation 0x00073768 __CFRunLoopDoSources0 + 376
15 CoreFoundation 0x00074504 __CFRunLoopRun + 224
16 CoreFoundation 0x0001d8e4 CFRunLoopRunSpecific + 224
17 CoreFoundation 0x0001d7ec CFRunLoopRunInMode + 52
18 GraphicsServices 0x000036e8 GSEventRunModal + 108
19 GraphicsServices 0x00003794 GSEventRun + 56
20 UIKit 0x000062a0 -[UIApplication _run] + 396
21 UIKit 0x00004e10 UIApplicationMain + 664
What could be wrong?
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
NSLog(#"Button Clicked!");
return YES;
}
- (void)webViewDidStartLoad:(UIWebView *)webView
{
orkutURLString = #"";
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:TRUE];
}
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
NSURL *currentURL = orkutWebView.request.mainDocumentURL;
NSLog(#"Relative URL: %#",[currentURL relativePath]);
NSArray *urllistItems = [[currentURL relativePath] componentsSeparatedByString:#"/"];
if([urllistItems count]>1)
{
orkutURLString = [urllistItems objectAtIndex:1];
orkutURLString = [orkutURLString lowercaseString];
if([orkutURLString isEqualToString:#"share"])
{
orkutWebView = nil;
[orkutWebView removeFromSuperview];
[orkutView removeFromSuperview];
NSString *message1 = NSLocalizedStringFromTableInBundle( #"Your status update was sent", #"Localizable", [NewfoxRadioAppDelegate GetLocalizebundle], #"");
UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:#"Newfox Radio" message:message1 delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alertView show];
[alertView release];
}
}
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:FALSE];
}
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:FALSE];
}
Got the solution. Got an NSZombie wherein I was releasing the object and then trying to access it. Got the desired result after I made use of Instruments to find out the NSZombie.

NSDictionary parsing Exception in iphone

I am using this code and it is giving exception
NSMutableArray *streams = (NSMutableArray *)[feed valueForKey:#"comments"];
NSMutableArray *streams1 = (NSMutableArray *)[streams valueForKey:#"data"];
//NSMutableArray *streams2 = (NSMutableArray *)[streams1 valueForKey:#"message"];
// loop over all the stream objects and print their titles
int index;
NSMutableDictionary *stream;
for (index = 0; index < [feed count];index++) {
stream = (NSMutableDictionary *)[streams1 objectAtIndex:index];
NSLog(#"Name of sender is: %#", [stream valueForKey:#"message"]);
}
FaceBookTable *detailViewController = [[FaceBookTable alloc] initWithNibName:#"FaceBookTable" bundle:nil];
// ...
// Pass the selected object to the new view controller.
detailViewController.fbGraph = fbGraph;
detailViewController.dummyArray = [ feed valueForKey:#"message"];
detailViewController.dict = stream;
}
Exception is
-[__NSArrayI isEqualToString:]: unrecognized selector sent to instance 0x5dae960
2011-06-15 16:14:07.835 MultiSocial[8042:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayI isEqualToString:]: unrecognized selector sent to instance 0x5dae960'
while my other code is working fine
NSMutableArray *streams = (NSMutableArray *)[feed valueForKey:#"from"];
lueForKey:#"message"];
// loop over all the stream objects and print their titles
int index;
NSMutableDictionary *stream;
for (index = 0; index < [feed count];index++) {
stream = (NSMutableDictionary *)[streams objectAtIndex:index];
NSLog(#"Name of sender is: %#", [stream valueForKey:#"message"]);
}
Please help
here is crash log
2011-06-15 17:05:42.148 MultiSocial[8583:207] -[__NSArrayI isEqualToString:]: unrecognized selector sent to instance 0x5d05f50
2011-06-15 17:05:42.156 MultiSocial[8583:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayI isEqualToString:]: unrecognized selector sent to instance 0x5d05f50'
*** Call stack at first throw:
(
0 CoreFoundation 0x013cabe9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x0151f5c2 objc_exception_throw + 47
2 CoreFoundation 0x013cc6fb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
3 CoreFoundation 0x0133c366 ___forwarding___ + 966
4 CoreFoundation 0x0133bf22 _CF_forwarding_prep_0 + 50
5 UIKit 0x00649405 -[UITableViewLabel setText:] + 84
6 MultiSocial 0x00046147 -[FaceBookTable tableView:cellForRowAtIndexPath:] + 467
7 UIKit 0x0045f7fa -[UITableView(UITableViewInternal) _createPreparedCellForGlobalRow:withIndexPath:] + 634
8 UIKit 0x0045577f -[UITableView(UITableViewInternal) _createPreparedCellForGlobalRow:] + 75
9 UIKit 0x0046a450 -[UITableView(_UITableViewPrivate) _updateVisibleCellsNow:] + 1561
10 UIKit 0x00462538 -[UITableView layoutSubviews] + 242
11 QuartzCore 0x01e98451 -[CALayer layoutSublayers] + 181
12 QuartzCore 0x01e9817c CALayerLayoutIfNeeded + 220
13 QuartzCore 0x01e9137c _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 310
14 QuartzCore 0x01e910d0 _ZN2CA11Transaction6commitEv + 292
15 QuartzCore 0x01ec17d5 _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 99
16 CoreFoundation 0x013abfbb __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 27
17 CoreFoundation 0x013410e7 __CFRunLoopDoObservers + 295
18 CoreFoundation 0x01309bd7 __CFRunLoopRun + 1575
19 CoreFoundation 0x01309240 CFRunLoopRunSpecific + 208
20 CoreFoundation 0x01309161 CFRunLoopRunInMode + 97
21 GraphicsServices 0x0190f268 GSEventRunModal + 217
22 GraphicsServices 0x0190f32d GSEventRun + 115
23 UIKit 0x003fa42e UIApplicationMain + 1160
24 MultiSocial 0x00002740 main + 102
25 MultiSocial 0x000026d1 start + 53
)
Well as per the crash log -[__NSArrayI isEqualToString:] there is some mistake in your code. It is clearly visible in the crash report that isEqualToString method is for NSString object but in your code it is called on NSArray.
Just debug your app and you will find the solution.
UPDATE
//Make sure that feed return an array for the key comments
NSArray *streams = (NSArray *)[feed valueForKey:#"comments"];
NSArray *streams1 = (NSArray *)[streams valueForKey:#"data"];
NSLog(#"comments : %#",streams);
//When you are running loop only last index value will be copied into your dictionary named stream so remove the loop.
FaceBookTable *detailViewController = [[FaceBookTable alloc] initWithNibName:#"FaceBookTable" bundle:nil];
// ...
// Pass the selected object to the new view controller.
detailViewController.fbGraph = fbGraph;
detailViewController.dummyArray = [ feed valueForKey:#"message"];
detailViewController.dict = streams;
}
//Your tableView cellForRowAtIndexPath method should look like this
//First get the dictionary
if(dict){
NSDictionary *stream = (NSDictionary *)[dict objectAtIndex:indexPath.row];
if(stream){
NSDictionary * messages = (NSDictionary *[stream valueForKey:#"Message"];
NSString *comment = [messages valueForKey:#"comment"];
cell.textLabel.text = comment;
}
}
u have been assigning the NSString object to NSArray.so do debug with breakpoints
NSMutableArray *arr = [[[feed valueForKey:#"comments"]valueForKey:#"data" ]valueForKey:#"id"];
for (NSString* cid in [arr objectAtIndex:0]) {
NSLog(#"cid is : %# \n\n",cid);
}