Terminating app due to uncaught exception 'NSRangeException' xcode 5 - ios

I got this error in a picker view function that getting its data to a text file from google spreadsheet.. this is the code of the function.
{
- (IBAction)clickText:(id)sender
int tag = [(UITextField*)sender tag];
if (tag!=11)
if (tag!=12)
if (tag!=13)
if (tag!=14)
if (tag!=15)
if (tag!=16)
if (tag!=17)
if (tag!=18)
if (tag!=19)
{
[sender resignFirstResponder];
}
self.myPicker.hidden = NO;
selectedTable = tag;
[sender resignFirstResponder];
float yy = 10;
switch (tag) {
case 11: yy = self.txtTgfeet.frame.origin.y + self.myPicker.frame.size.height;
break;
case 12: yy = self.txtTginches.frame.origin.y + self.myPicker.frame.size.height;
break;
case 13: yy = self.txtTgfraction.frame.origin.y + self.myPicker.frame.size.height;
break;
case 14: yy = self.txtBgfeet.frame.origin.y - self.myPicker.frame.size.height;
break;
case 15: yy = self.txtBginches.frame.origin.y - self.myPicker.frame.size.height;
break;
case 16: yy = self.txtBgfraction.frame.origin.y - self.myPicker.frame.size.height;
break;
case 17: yy = self.txtGravity.frame.origin.y - self.myPicker.frame.size.height;
break;
case 18: yy = self.txtBsw.frame.origin.y - self.myPicker.frame.size.height;
break;
case 19: yy = self.txtTemp.frame.origin.y - self.myPicker.frame.size.height;
break;
default:
break;
}
[self.myPicker setFrame:CGRectMake(self.txtTgfeet.frame.origin.x, yy, self.txtTgfeet.frame.size.width, 216)];
[self.ar removeAllObjects];
NSString *theURL = #"https://docs.google.com/spreadsheet/pub?key=0AobIgii9hBGPdDJ3TmgxSkRzVFBKWXVnTWdQcGtyMFE&single=true&gid=9&output=txt";
NSString *theFile = [NSString stringWithContentsOfURL:[NSURL URLWithString:theURL] encoding:NSUTF8StringEncoding error:nil];
NSLog(#"%#",theFile);
NSArray *theCells = [theFile componentsSeparatedByString:#"\n"];
for (int i=1; i < [theCells count]; i++)
{
// if (i > 0)
{
NSArray *value =[[theCells objectAtIndex:i] componentsSeparatedByString:#"\t"];
[self.ar addObject:[value objectAtIndex:tag+1]];
}
}
[self.myPicker selectRow:0 inComponent:0 animated:NO];
[self.myPicker reloadAllComponents];
This function is working perfectly on the other app, I've made this only for another app that I want this feature. Now when I click the text field I am getting this error:
Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 12 beyond bounds [0 .. 8]'
*** First throw call stack:
(
0 CoreFoundation 0x01b575e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x018da8b6 objc_exception_throw + 44
2 CoreFoundation 0x01af84e6 -[__NSArrayM objectAtIndex:] + 246
3 TGC 0x000080ba -[MainViewController clickText:] + 4602
4 libobjc.A.dylib 0x018ec81f -[NSObject performSelector:withObject:] + 70
5 UIKit 0x0043d0c2 -[UIApplication sendAction:to:from:forEvent:] + 108
6 UIKit 0x0043d04e -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 61
7 UIKit 0x005350c1 -[UIControl sendAction:to:forEvent:] + 66
8 UIKit 0x00535484 -[UIControl _sendActionsForEvents:withEvent:] + 577
9 UIKit 0x00b222ae -[UITextField willAttachFieldEditor:] + 685
10 UIKit 0x0053aeb5 -[UIFieldEditor becomeFieldEditorForView:] + 927
11 UIKit 0x00b193a3 -[UITextField _becomeFirstResponder] + 160
12 UIKit 0x00594ef5 -[UIResponder becomeFirstResponder] + 400
13 UIKit 0x0049819b -[UIView(Hierarchy) becomeFirstResponder] + 114
14 UIKit 0x00b18e43 -[UITextField becomeFirstResponder] + 51
15 UIKit 0x007bd551 -[UITextInteractionAssistant(UITextInteractionAssistant_Internal) setFirstResponderIfNecessary] + 135
16 UIKit 0x007bfaa2 -[UITextInteractionAssistant(UITextInteractionAssistant_Internal) oneFingerTap:] + 2640
17 UIKit 0x007b3e8c _UIGestureRecognizerSendActions + 230
18 UIKit 0x007b2b00 -[UIGestureRecognizer _updateGestureWithEvent:buttonEvent:] + 383
19 UIKit 0x007b456d -[UIGestureRecognizer _delayedUpdateGesture] + 60
20 UIKit 0x007b7acd ___UIGestureRecognizerUpdate_block_invoke + 57
21 UIKit 0x007b7a4e _UIGestureRecognizerRemoveObjectsFromArrayAndApplyBlocks + 317
22 UIKit 0x007ae148 _UIGestureRecognizerUpdate + 199
23 UIKit 0x0047a19a -[UIWindow _sendGesturesForEvent:] + 1291
24 UIKit 0x0047b0ba -[UIWindow sendEvent:] + 1030
25 UIKit 0x0044ee86 -[UIApplication sendEvent:] + 242
26 UIKit 0x0043918f _UIApplicationHandleEventQueue + 11421
27 CoreFoundation 0x01ae083f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
28 CoreFoundation 0x01ae01cb __CFRunLoopDoSources0 + 235
29 CoreFoundation 0x01afd29e __CFRunLoopRun + 910
30 CoreFoundation 0x01afcac3 CFRunLoopRunSpecific + 467
31 CoreFoundation 0x01afc8db CFRunLoopRunInMode + 123
32 GraphicsServices 0x031bb9e2 GSEventRunModal + 192
33 GraphicsServices 0x031bb809 GSEventRun + 104
34 UIKit 0x0043bd3b UIApplicationMain + 1225
35 TGC 0x00002d62 main + 130
36 libdyld.dylib 0x022fd725 start + 0
37 ??? 0x00000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
what is seems to be the problem here?

Here it is clearly mentioned that [__NSArrayM objectAtIndex:]: index 12 beyond bounds [0 .. 8]'
You are trying to access 12th [index 12 and array has 0 to 8 object only] element which is not present, so application is crashing.
Using break point check below line,
[self.ar addObject:[value objectAtIndex:tag+1]];

Your problem seems to be here:
[value objectAtIndex:tag+1]
You are accessing the index 12, when your array value only contains 9 elements.

NSArray *value =[[theCells objectAtIndex:i] componentsSeparatedByString:#"\t"];
if ([value count]>tag+1) {
[self.ar addObject:[value objectAtIndex:tag+1]];
}

Related

The Application crashes at replaceobjectatindex

The application crashes at replaceobjectatindex .
The clickedbuttonpath.row returns nil value . Need help .
- (void)textFieldDidEndEditing:(UITextField *)textField
{
if (textField.text.length>0)
{
UITableViewCell *clickedCell = (UITableViewCell *)[[textField superview] superview];
NSIndexPath *clickedButtonPath = [addSizesTableView_ indexPathForCell:clickedCell];
if (textField.tag==6)
{
[textDic setObject:textField.text forKey:clickedButtonPath];
[orderArr replaceObjectAtIndex:clickedButtonPath.row withObject:textField.text];
This is the crash log which am getting .
'NSInvalidArgumentException', reason: '* setObjectForKey: key cannot be nil'
* First throw call stack:
(
0 CoreFoundation 0x0000000106d1ef35 exceptionPreprocess + 165
1 libobjc.A.dylib 0x00000001062acbb7 objc_exception_throw + 45
2 CoreFoundation 0x0000000106c25998 -[__NSDictionaryM setObject:forKey:] + 968
3 BookMyStock 0x0000000103559ac0 -[AddSizesOfColors textFieldDidEndEditing:] + 368
4 UIKit 0x0000000105289549 -[UITextField _resignFirstResponder] + 382
5 UIKit 0x0000000104ccc4f5 -[UIResponder resignFirstResponder] + 236
6 UIKit 0x00000001052892d4 -[UITextField resignFirstResponder] + 114
7 UIKit 0x0000000105295953 -[UIView(UITextField) endEditing:] + 173
8 BookMyStock 0x0000000103557c2d -[AddSizesOfColors addTFTotheView] + 285
9 UIKit 0x0000000104b568be -[UIApplication sendAction:to:from:forEvent:] + 75
10 UIKit 0x0000000104c5d410 -[UIControl _sendActionsForEvents:withEvent:] + 467
11 UIKit 0x0000000104c5c7df -[UIControl touchesEnded:withEvent:] + 522
12 UIKit 0x0000000104b9c308 -[UIWindow _sendTouchesForEvent:] + 735
13 UIKit 0x0000000104b9cc33 -[UIWindow sendEvent:] + 683
14 UIKit 0x0000000104b699b1 -[UIApplication sendEvent:] + 246
15 UIKit 0x0000000104b76a7d _UIApplicationHandleEventFromQueueEvent + 17370
16 UIKit 0x0000000104b52103 _UIApplicationHandleEventQueue + 1961
17 CoreFoundation 0x0000000106c54551 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION + 17
18 CoreFoundation 0x0000000106c4a41d __CFRunLoopDoSources0 + 269
19 CoreFoundation 0x0000000106c49a54 __CFRunLoopRun + 868
20 CoreFoundation 0x0000000106c49486 CFRunLoopRunSpecific + 470
21 GraphicsServices 0x0000000108bdc9f0 GSEventRunModal + 161
22 UIKit 0x0000000104b55420 UIApplicationMain + 1282
23 BookMyStock 0x0000000103492913 main + 115
24 libdyld.dylib 0x0000000107c7e145 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
[[textField superview] superview] returns nil, incase of iOS 8, whereas in iOS 7 it returns some value. As suggested in below link, don't rely on view hierarchy.
You can check this link Getting UITableViewCell from its superview iOS 7 issue
You can try below like structure
CGPoint subviewPosition = [textField convertPoint:CGPointZero toView:self.tableView];
NSIndexPath* clickedButtonPath = [addSizesTableView_ indexPathForRowAtPoint:subviewPosition];

[_NSArrayM objectAtIndex:]: index 4294967295 beyond bounds [0..1]

I'm using a simulator for iphone 4s(iOS 7.0.3) for my app and I get the following error
*** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 4294967295 beyond bounds [0 .. 1]'
*** First throw call stack:
(
0 CoreFoundation 0x003085e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x027568b6 objc_exception_throw + 44
2 CoreFoundation 0x002a94e6 -[__NSArrayM objectAtIndex:] + 246
3 Requisitions 0x0015007a -[PasswordLoginController3 _adjustInputPos] + 61
4 Requisitions 0x0015042a -[PasswordLoginController3 keyboardWasShown:] + 312
5 Foundation 0x02428bf9 __57-[NSNotificationCenter addObserver:selector:name:object:]_block_invoke + 40
6 CoreFoundation 0x00364524 __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 20
7 CoreFoundation 0x002bc00b _CFXNotificationPost + 2859
8 Foundation 0x02362951 -[NSNotificationCenter postNotificationName:object:userInfo:] + 98
9 UIKit 0x009ffb1b -[UIInputViewTransition postNotificationsForTransitionEnd] + 1054
10 UIKit 0x009f6138 __53-[UIPeripheralHost(UIKitInternal) executeTransition:]_block_invoke1332 + 455
11 UIKit 0x006993c0 -[UINavigationControllerKeyboardAnimationStyle launchAnimation:afterStarted:completion:forHost:fromCurrentPosition:] + 501
12 UIKit 0x009f5a7c -[UIPeripheralHost(UIKitInternal) executeTransition:] + 1258
13 UIKit 0x009f7c0e -[UIPeripheralHost(UIKitInternal) setInputViews:animationStyle:] + 1029
14 UIKit 0x009f8019 -[UIPeripheralHost(UIKitInternal) setInputViews:animated:] + 72
15 UIKit 0x009f8063 -[UIPeripheralHost(UIKitInternal) setInputViews:] + 67
16 UIKit 0x009ef2fa -[UIPeripheralHost(UIKitInternal) _reloadInputViewsForResponder:] + 1453
17 UIKit 0x006c969a -[UIResponder(UIResponderInputViewAdditions) reloadInputViews] + 287
18 UIKit 0x006c8f8b -[UIResponder becomeFirstResponder] + 550
19 UIKit 0x005cc19b -[UIView(Hierarchy) becomeFirstResponder] + 114
20 UIKit 0x00c4ce43 -[UITextField becomeFirstResponder] + 51
21 UIKit 0x005cc1e8 -[UIView(Hierarchy) deferredBecomeFirstResponder] + 67
22 UIKit 0x005cc27c -[UIView(Hierarchy) _promoteSelfOrDescendantToFirstResponderIfNecessary] + 115
23 UIKit 0x005cc53e __45-[UIView(Hierarchy) _postMovedFromSuperview:]_block_invoke + 224
24 UIKit 0x005cc388 -[UIView(Hierarchy) _postMovedFromSuperview:] + 260
25 UIKit 0x005d74c1 -[UIView(Internal) _addSubview:positioned:relativeTo:] + 1847
26 UIKit 0x005ca9b1 -[UIView(Hierarchy) addSubview:] + 56
27 UIKit 0x00563848 __53-[_UINavigationParallaxTransition animateTransition:]_block_invoke + 1927
28 UIKit 0x005d13ef +[UIView(Animation) performWithoutAnimation:] + 82
29 UIKit 0x00562c96 -[_UINavigationParallaxTransition animateTransition:] + 1155
30 UIKit 0x0069de4e -[UINavigationController _startCustomTransition:] + 3446
31 UIKit 0x006aa0c7 -[UINavigationController _startDeferredTransitionIfNeeded:] + 688
32 UIKit 0x006aacb9 -[UINavigationController __viewWillLayoutSubviews] + 57
33 UIKit 0x007e4181 -[UILayoutContainerView layoutSubviews] + 213
34 UIKit 0x005da267 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 355
35 libobjc.A.dylib 0x0276881f -[NSObject performSelector:withObject:] + 70
36 QuartzCore 0x022182ea -[CALayer layoutSublayers] + 148
37 QuartzCore 0x0220c0d4 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 380
38 QuartzCore 0x0220bf40 _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 26
39 QuartzCore 0x02173ae6 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 294
40 QuartzCore 0x02174e71 _ZN2CA11Transaction6commitEv + 393
41 QuartzCore 0x02175544 _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 92
42 CoreFoundation 0x002d04ce __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 30
43 CoreFoundation 0x002d041f __CFRunLoopDoObservers + 399
44 CoreFoundation 0x002ae344 __CFRunLoopRun + 1076
45 CoreFoundation 0x002adac3 CFRunLoopRunSpecific + 467
46 CoreFoundation 0x002ad8db CFRunLoopRunInMode + 123
47 GraphicsServices 0x03ce39e2 GSEventRunModal + 192
48 GraphicsServices 0x03ce3809 GSEventRun + 104
49 UIKit 0x0056fd3b UIApplicationMain + 1225
50 Requisitions 0x000a712c main + 92
51 libdyld.dylib 0x03036701 start + 1
52 ??? 0x00000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
I tried this thread CRASH: *** -[__NSArrayM objectAtIndex:]: index 4294967295 beyond bounds [0 .. 9] and tried to debug at certain breakpoint, but no avail. I couldn't figure out where the issue is happening. Objective C is not my forte , but still fixing this issue.
Method _adjustInputPos
-(void) _adjustInputPos
{
UITextField *currentField = [inputFields objectAtIndex:currentInputIndex];
CGFloat currentInputHeight = currentField.frame.origin.y;
UIView* v = [self.formView viewWithTag:70];
if(v!=nil) {
currentInputHeight += v.frame.origin.y;
}
UIScrollView* sv = (UIScrollView*)self.view;
CGFloat offset = 0;
if (sv.contentOffset.y>=(currentInputHeight)) {
offset = (sv.frame.size.height-kbHeight)/1.5;
} else if((self.view.frame.size.height-kbHeight-currentInputHeight)<currentField.frame.size.height) {
offset = (sv.frame.size.height-kbHeight)/1.5;
} else {
return;
}
if(sv.contentOffset.y==offset) {
return;
}
CGPoint scrollPoint = CGPointMake(0.0, offset);
[sv setContentOffset:scrollPoint animated:YES];
}
Method keyBoardWasShown
- (void) keyboardWasShown:(NSNotification*)notf
{
if(isHidden) {
return;
}
NSDictionary *info = [notf userInfo];
CGSize kbSize = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
kbHeight = kbSize.height;
BOOL islandscape = [[ClientAuthenticator getInstance].actionHandler isLandscape];
if(!islandscape && [LSUtility isTablet]) {//ipad portrait,no need.
return;
}
if(islandscape ) {
kbHeight = kbSize.width;
}
if (is30Style) {
[self _adjustInputPos];
} else {
[self _adjustInputPos31];
}
UIScrollView *sv = (UIScrollView*)self.view;
CGSize size = CGSizeMake(sv.frame.size.width, sv.frame.size.height+kbHeight/1.5);
[sv setContentSize:size];
}
Thanks
4294967295 is 0xFFFFFFFF in hex, or -1 as an unsigned int.
Check in [PasswordLoginController3 _adjustInputPos] - it is asking for objectAtIndex with the value -1 (which is out of bounds).
Edit since you added code
UITextField *currentField = [inputFields objectAtIndex:currentInputIndex]
This looks to be the line that the error comes from. What is the type of currentInputIndex and where is it initialised/modified?

Xcode 5 - No Crash or no console logs

Team,
I got a crash when I perform below actions in my simulator,
> Navigated to Screen1 - > Screen2- > Screen3 -> Screen2 -> screen1
> Press home screen - Go to iPhone Settings screen -> Relaunch my application
> then perform the same steps (Screen1 - > Screen2- > Screen3 -> Screen2 -> screen1)
> perform the same steps Screen1 -> screen2 -> Screen3 -> CRASH on [super viewDidLoad]
I don't see any crash logs or console logs for the crash, but my debugger stops at this point.
Any idea why my application crashes only when I minimized and relaunch the application. If I don't minimize the application, everything works as expected.
Why I am not able to view any console logs for the crash?
Note: We tested on iOS6 device and there is no crash, this is observed only in iOS7 device. I can reproduce the crash only when I minimize the application, else it works fine.
seen this log only once,
2014-04-16 11:42:05.073 ADTCommercial[36614:60b] -[CALayerArray leading]: unrecognized selector sent to instance 0xac1a690
2014-04-16 11:42:05:077 ADTCommercial[36614:60b]
*÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷*
* An Exception Has Been Handled! *
Method:
-[ADT_TaskHomeList(Custom) tableView:didSelectRowAtIndexPath:] -
Exception Name:
NSInvalidArgumentException
Exception Reason:
-[CALayerArray leading]: unrecognized selector sent to instance 0xac1a690
StackTrace:
0 CoreFoundation 0x031af1e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x03d7e8e5 objc_exception_throw + 44
2 CoreFoundation 0x0324c243 -[NSObject(NSObject) doesNotRecognizeSelector:] + 275
3 CoreFoundation 0x0319f50b ___forwarding___ + 1019
4 CoreFoundation 0x0319f0ee _CF_forwarding_prep_0 + 14
5 ADTCommercial 0x005aa1d1 +[AMPListScreenTableViewCell getHeightForFont:numberOfLines:] + 113
6 ADTCommercial 0x0059dd80 -[AMPGeneratedListViewController invalidate] + 224
7 ADTCommercial 0x0059e4f8 -[AMPGeneratedListViewController setNumberOfLines:] + 360
8 ADTCommercial 0x0059d28e -[AMPGeneratedListViewController viewDidLoad] + 270
9 ADTCommercial 0x00107208 -[ADT_SystemDetails(Custom) viewDidLoad] + 72
10 UIKit 0x02122e10 -[UIViewController awakeFromNib] + 110
11 UIKit 0x022bbf67 -[UINib instantiateWithOwner:options:] + 1955
12 UIKit 0x022bdada -[NSBundle(UINSBundleAdditions) loadNibNamed:owner:options:] + 165
13 ADTCommercial 0x005c1f7b -[AMPViewManager loadView] + 811
14 ADTCommercial 0x005b6916 -[AMPScreenManager showScreen:withRow:createScreen:reloadPolicy:doReset:isModal:animated:navigationController:] + 3542
15 ADTCommercial 0x0058b1ec +[AMPStandardActions gotoAction:reloadPolicy:transactionStateChange:addToHistory:] + 252
16 ADTCommercial 0x002c4935 -[ADT_TaskHomeList(Custom) tableView:didSelectRowAtIndexPath:] + 901
17 UIKit 0x020f09a1 -[UITableView _selectRowAtIndexPath:animated:scrollPosition:notifyDelegate:] + 1513
18 UIKit 0x020f0b14 -[UITableView _userSelectRowAtPendingSelectionIndexPath:] + 279
19 UIKit 0x020f510e __38-[UITableView touchesEnded:withEvent:]_block_invoke + 43
20 UIKit 0x020240aa ___afterCACommitHandler_block_invoke + 15
21 UIKit 0x02024055 _applyBlockToCFArrayCopiedToStack + 403
22 UIKit 0x02023e76 _afterCACommitHandler + 532
23 CoreFoundation 0x0317736e __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 30
24 CoreFoundation 0x031772bf __CFRunLoopDoObservers + 399
25 CoreFoundation 0x03155254 __CFRunLoopRun + 1076
26 CoreFoundation 0x031549d3 CFRunLoopRunSpecific + 467
27 CoreFoundation 0x031547eb CFRunLoopRunInMode + 123
28 GraphicsServices 0x04e805ee GSEventRunModal + 192
29 GraphicsServices 0x04e8042b GSEventRun + 104
30 UIKit 0x02006f9b UIApplicationMain + 1225
31 ADTCommercial 0x0000642e main + 126
32 libdyld.dylib 0x044c4701 start + 1
33 ??? 0x00000001 0x0 + 1
*÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷*
-(void)tableView:(UITableView *)table didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
PMPCAccountInfoTabScreen *accountsInfoTabScreen = nil;
PMPCJobWrapUp *wrapUpScreen = nil;
NSString *screenPushedUnderJobWrapUp = #"SCREEN_PUSHED_UNDER_WRAP_UP";
#try {
switch (indexPath.row) {
case 0:
// PUSH THE ACCOUNT INFORMATION SCREEN
accountsInfoTabScreen = (PMPCAccountInfoTabScreen*)[[[PMPCScreenManager sharedScreenManager] getScreen:#"PMPCAccountInfoTabScreen"] view];
[accountsInfoTabScreen setSelectedTab:0];
[PMPCStandardActions gotoAction:#"PMPCAccountInfoTabScreen" reloadPolicy:PMPCScreenReloadAlways transactionStateChange:PMPCTransactionContinue addToHistory:YES];
[Commons setClipboardValueForKey:screenPushedUnderJobWrapUp value:[NSNumber numberWithBool:NO]];
break;
case 1:
// PUSH THE JOB DETAILS SCREEN
[PMPCStandardActions gotoAction:#"JobDetailsScreen" reloadPolicy:PMPCScreenReloadAlways transactionStateChange:PMPCTransactionContinue addToHistory:YES];
[Commons setClipboardValueForKey:screenPushedUnderJobWrapUp value:[NSNumber numberWithBool:NO]];
break;
case 2:
//[[PMPCDataClipboard sharedClipboard] setValueForKey:screenPushedUnderJobWrapUp value:[NSNumber numberWithBool:NO]];
[[PMPCDataClipboard sharedClipboard] removeValueForKey:screenPushedUnderJobWrapUp];
[Commons setClipboardValueForKey:screenPushedUnderJobWrapUp value:[NSNumber numberWithBool:NO]];
[PMPCStandardActions gotoAction:#"PMPCSystemDetails" reloadPolicy:PMPCScreenReloadAlways transactionStateChange:PMPCTransactionContinue addToHistory:YES];
break;
case 3:
// Add Items screen
[Commons setClipboardValueForKey:screenPushedUnderJobWrapUp value:[NSNumber numberWithBool:NO]];
[PMPCStandardActions gotoAction:#"PMPCAddedItemsList" reloadPolicy:PMPCScreenReloadAlways transactionStateChange:PMPCTransactionContinue addToHistory:YES];
break;
case 4:
// PUSH THE JOB WRAP UP SCREEN
//JobWrapUpObject *wrapUp = [Commons getJobWrapUpObject];
//[wrapUp resetValues];
wrapUpScreen = (PMPCJobWrapUp*)[[[PMPCScreenManager sharedScreenManager] getScreen:#"PMPCJobWrapUp"] view];
[wrapUpScreen setScrollToTop:YES];
[Commons setClipboardValueForKey:screenPushedUnderJobWrapUp value:[NSNumber numberWithBool:YES]];
[PMPCStandardActions gotoAction:#"PMPCJobWrapUp" reloadPolicy:PMPCScreenReloadAlways transactionStateChange:PMPCTransactionBegin addToHistory:YES];
break;
default:
break;
}
}
#catch (NSException *exception) {
ExceptionLog(exception);
}
#finally {
[PMPCLog trace:#"%s Ends",__PRETTY_FUNCTION__];
}
}
Thanks,
Ramesh

SIGABRT error - segmented control

i have a segmented control which, depending on what is selected, is meant to allocate a value to a NS string, as follows:
-(IBAction)driverKnownIndexChanged{
switch (self.driverKnown.selectedSegmentIndex) {
case 0:
driverKnownResponse = #"Yes";
break;
case 1:
driverKnownResponse = #"No";
break;
default:
break;
}
}
however, it is throwing a SIGABRT at the following line:
#import "RoadSafetyAppAppDelegate.h"
int main(int argc, char * argv[])
{
#autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([RoadSafetyAppAppDelegate class]));
}
}
and here is the console output:
2014-01-30 13:32:16.403 Road Safety App V2[3873:70b] -[DobInAHoonViewController driverKnown:]: unrecognized selector sent to instance 0xcd23440
2014-01-30 13:32:16.409 Road Safety App V2[3873:70b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[DobInAHoonViewController driverKnown:]: unrecognized selector sent to instance 0xcd23440'
*** First throw call stack:
(
0 CoreFoundation 0x01d8f7e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x01b0f8e5 objc_exception_throw + 44
2 CoreFoundation 0x01e2c843 -[NSObject(NSObject) doesNotRecognizeSelector:] + 275
3 CoreFoundation 0x01d7fb0b ___forwarding___ + 1019
4 CoreFoundation 0x01d7f6ee _CF_forwarding_prep_0 + 14
5 libobjc.A.dylib 0x01b2182b -[NSObject performSelector:withObject:] + 70
6 UIKit 0x007d8309 -[UIApplication sendAction:to:from:forEvent:] + 108
7 UIKit 0x007d8295 -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 61
8 UIKit 0x008d90a1 -[UIControl sendAction:to:forEvent:] + 66
9 UIKit 0x008d9496 -[UIControl _sendActionsForEvents:withEvent:] + 577
10 UIKit 0x008d90d6 -[UIControl sendActionsForControlEvents:] + 48
11 UIKit 0x00947572 -[UISegmentedControl _setSelectedSegmentIndex:notify:animate:] + 598
12 UIKit 0x009498c3 -[UISegmentedControl touchesEnded:withEvent:] + 175
13 UIKit 0x00b6ccc3 _UIGestureRecognizerUpdate + 7166
14 UIKit 0x008177ca -[UIWindow _sendGesturesForEvent:] + 1291
15 UIKit 0x008186e1 -[UIWindow sendEvent:] + 1021
16 UIKit 0x007ea542 -[UIApplication sendEvent:] + 242
17 UIKit 0x007d42f3 _UIApplicationHandleEventQueue + 11455
18 CoreFoundation 0x01d18d7f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
19 CoreFoundation 0x01d1870b __CFRunLoopDoSources0 + 235
20 CoreFoundation 0x01d357ae __CFRunLoopRun + 910
21 CoreFoundation 0x01d34fd3 CFRunLoopRunSpecific + 467
22 CoreFoundation 0x01d34deb CFRunLoopRunInMode + 123
23 GraphicsServices 0x0344f4ed GSEventRunModal + 192
24 GraphicsServices 0x0344f32a GSEventRun + 104
25 UIKit 0x007d6eeb UIApplicationMain + 1225
26 Road Safety App V2 0x00002f9d main + 141
27 libdyld.dylib 0x0308470d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
and Ideas as to why i am having this problem? and a solution would also be appreciated.
This line switch (self.driverKnown.selectedSegmentIndex) { is accessing a property named driverKnown but that driver is unknown. The stack trace and exception are telling you that driverKnown is an undeclared or unknock getter method for the property.
The exception calls out DobInAHoonViewController which in that line of code would be the self. Is driverKnown suppose to be the name of your UISegmentedControl? Can we see the creation of said UISegmentedControl?
your method doesn't know selectedSegmentIndex . because you not value of segment value changed
UISegmentControl *mySegmentedControl = [[UISegmentControl alloc]init];
[mySegmentedControl addTarget:self action:#selector(segmentValueChanged:) forControlEvents:UIControlEventValueChanged];
- (IBAction)segmentValueChanged:(id)sender {
UISegmentedControl *driverKnown = (UISegmentedControl *)sender;
switch (driverKnown.selectedSegmentIndex) {
case 0:
driverKnownResponse = #"Yes";
break;
case 1:
driverKnownResponse = #"No";
break;
default:
break;
}
}

Xcode: App crashes because I deleted a class no other class uses anymore?

Very strange behaviour...I've used before an NSNumber category called NSNumber+Currencies. Yesterday I've changed everything including core data to NSDecimalNumber so I have now a class NSDecimalNumber+Currencies. There is really no link at all! to NSNumber+Currencies anymore. However if I delete it and try to run my app in the simulator, my app crashes with the message "unrecognized selector sent to instance ..." This instance is a NSDecimalNumber and the methods I use in this category are basically the same as before. And I really import ONLY the NSDecimalNumber+Currencies. But it makes no sense...I've deleted the app from the simulator, cleaned my project, closed Xcode, removed the old category even manually from the build phases but nothing helps..is there another trick? If I leave this old category in it it runs smoothly...
My error log. However after the 2nd run my app doesn't start at all and the error message is a different one:
2014-01-28 11:51:29.458 NetIncome[2341:70b] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayI objectAtIndex:]: index 0 beyond bounds for empty array'
*** First throw call stack:
(
0 CoreFoundation 0x01ecf5e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x01abe8b6 objc_exception_throw + 44
2 CoreFoundation 0x01e839c2 -[__NSArrayI objectAtIndex:] + 210
3 CoreData 0x01899c1f -[NSFetchedResultsController objectAtIndexPath:] + 255
4 NetIncome 0x00003dee -[MainCategoriesViewController tableView:cellForRowAtIndexPath:] + 206
5 UIKit 0x003ac61f -[UITableView _createPreparedCellForGlobalRow:withIndexPath:] + 412
6 UIKit 0x003ac6f3 -[UITableView _createPreparedCellForGlobalRow:] + 69
7 UIKit 0x00390774 -[UITableView _updateVisibleCellsNow:] + 2378
8 UIKit 0x0038eb81 -[UITableView _updateVisibleCellsImmediatelyIfNecessary] + 66
9 UIKit 0x0039cb5f -[UITableView _visibleCells] + 35
10 UIKit 0x0039cbb4 -[UITableView visibleCells] + 33
11 UIKit 0x0039fcc0 -[UITableView setSeparatorStyle:] + 115
12 NetIncome 0x000037d4 -[MainCategoriesViewController styleTableView] + 100
13 NetIncome 0x0000300a -[MainCategoriesViewController viewDidLoad] + 1194
14 UIKit 0x003d1318 -[UIViewController loadViewIfRequired] + 696
15 UIKit 0x003f6b15 -[UINavigationController _layoutViewController:] + 39
16 UIKit 0x003f702b -[UINavigationController _updateScrollViewFromViewController:toViewController:] + 235
17 UIKit 0x003f7123 -[UINavigationController _startTransition:fromViewController:toViewController:] + 78
18 UIKit 0x003f809c -[UINavigationController _startDeferredTransitionIfNeeded:] + 645
19 UIKit 0x003f8cb9 -[UINavigationController __viewWillLayoutSubviews] + 57
20 UIKit 0x00532181 -[UILayoutContainerView layoutSubviews] + 213
21 UIKit 0x00328267 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 355
22 libobjc.A.dylib 0x01ad081f -[NSObject performSelector:withObject:] + 70
23 QuartzCore 0x001972ea -[CALayer layoutSublayers] + 148
24 QuartzCore 0x0018b0d4 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 380
25 QuartzCore 0x00197235 -[CALayer layoutIfNeeded] + 160
26 UIKit 0x003e3613 -[UIViewController window:setupWithInterfaceOrientation:] + 304
27 UIKit 0x00302177 -[UIWindow _setRotatableClient:toOrientation:updateStatusBar:duration:force:isRotating:] + 5212
28 UIKit 0x00300d16 -[UIWindow _setRotatableClient:toOrientation:updateStatusBar:duration:force:] + 82
29 UIKit 0x00300be8 -[UIWindow _setRotatableViewOrientation:updateStatusBar:duration:force:] + 117
30 UIKit 0x00300c70 -[UIWindow _setRotatableViewOrientation:duration:force:] + 67
31 UIKit 0x002ffd0a __57-[UIWindow _updateToInterfaceOrientation:duration:force:]_block_invoke + 120
32 UIKit 0x002ffc6c -[UIWindow _updateToInterfaceOrientation:duration:force:] + 400
33 UIKit 0x003009c3 -[UIWindow setAutorotates:forceUpdateInterfaceOrientation:] + 870
34 UIKit 0x00303fb6 -[UIWindow setDelegate:] + 449
35 UIKit 0x003d5737 -[UIViewController _tryBecomeRootViewControllerInWindow:] + 180
36 UIKit 0x002f9c1c -[UIWindow addRootViewControllerViewIfPossible] + 609
37 UIKit 0x002f9d97 -[UIWindow _setHidden:forced:] + 312
38 UIKit 0x002fa02d -[UIWindow _orderFrontWithoutMakingKey] + 49
39 UIKit 0x0030489a -[UIWindow makeKeyAndVisible] + 65
40 UIKit 0x002b7cd0 -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] + 1851
41 UIKit 0x002bc3a8 -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 824
42 UIKit 0x002d087c -[UIApplication handleEvent:withNewEvent:] + 3447
43 UIKit 0x002d0de9 -[UIApplication sendEvent:] + 85
44 UIKit 0x002be025 _UIApplicationHandleEvent + 736
45 GraphicsServices 0x035202f6 _PurpleEventCallback + 776
46 GraphicsServices 0x0351fe01 PurpleEventCallback + 46
47 CoreFoundation 0x01e4ad65 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 53
48 CoreFoundation 0x01e4aa9b __CFRunLoopDoSource1 + 523
49 CoreFoundation 0x01e7577c __CFRunLoopRun + 2156
50 CoreFoundation 0x01e74ac3 CFRunLoopRunSpecific + 467
51 CoreFoundation 0x01e748db CFRunLoopRunInMode + 123
52 UIKit 0x002bbadd -[UIApplication _run] + 840
53 UIKit 0x002bdd3b UIApplicationMain + 1225
54 NetIncome 0x000027ad main + 141
55 libdyld.dylib 0x031c070d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
EDIT2: And this is the original error message, only shown once and immediately after deleting the relevant files:
2014-01-28 12:00:15.598 NetIncome[2872:70b] -[__NSCFNumber getLocalizedCurrencyString]: unrecognized selector sent to instance 0x8c59720
2014-01-28 12:00:15.602 NetIncome[2872:70b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFNumber getLocalizedCurrencyString]: unrecognized selector sent to instance 0x8c59720'
*** First throw call stack:
(
0 CoreFoundation 0x01ecf5e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x01abe8b6 objc_exception_throw + 44
2 CoreFoundation 0x01f6c903 -[NSObject(NSObject) doesNotRecognizeSelector:] + 275
3 CoreFoundation 0x01ebf90b ___forwarding___ + 1019
4 CoreFoundation 0x01ebf4ee _CF_forwarding_prep_0 + 14
5 NetIncome 0x000358da -[NetIncomeViewController viewDidLoad] + 954
6 UIKit 0x003d1318 -[UIViewController loadViewIfRequired] + 696
7 UIKit 0x003f6b15 -[UINavigationController _layoutViewController:] + 39
8 UIKit 0x003f702b -[UINavigationController _updateScrollViewFromViewController:toViewController:] + 235
9 UIKit 0x003f7123 -[UINavigationController _startTransition:fromViewController:toViewController:] + 78
10 UIKit 0x003f809c -[UINavigationController _startDeferredTransitionIfNeeded:] + 645
11 UIKit 0x003f8cb9 -[UINavigationController __viewWillLayoutSubviews] + 57
12 UIKit 0x00532181 -[UILayoutContainerView layoutSubviews] + 213
13 UIKit 0x00328267 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 355
14 libobjc.A.dylib 0x01ad081f -[NSObject performSelector:withObject:] + 70
15 QuartzCore 0x001972ea -[CALayer layoutSublayers] + 148
16 QuartzCore 0x0018b0d4 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 380
17 QuartzCore 0x0018af40 _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 26
18 QuartzCore 0x000f2ae6 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 294
19 QuartzCore 0x000f3e71 _ZN2CA11Transaction6commitEv + 393
20 QuartzCore 0x001b0430 +[CATransaction flush] + 52
21 UIKit 0x002d9dc9 _afterCACommitHandler + 131
22 CoreFoundation 0x01e974ce __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 30
23 CoreFoundation 0x01e9741f __CFRunLoopDoObservers + 399
24 CoreFoundation 0x01e75344 __CFRunLoopRun + 1076
25 CoreFoundation 0x01e74ac3 CFRunLoopRunSpecific + 467
26 CoreFoundation 0x01e748db CFRunLoopRunInMode + 123
27 GraphicsServices 0x0351e9e2 GSEventRunModal + 192
28 GraphicsServices 0x0351e809 GSEventRun + 104
29 UIKit 0x002bdd3b UIApplicationMain + 1225
30 NetIncome 0x00002b3d main + 141
31 libdyld.dylib 0x031c070d start + 1
32 ??? 0x00000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
The lines of code my app crashes the first time (the last line is the one):
//Get or set and get the gross income
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSDecimalNumber *grossIncome = [defaults objectForKey:#"grossincome"];
if (!grossIncome) {
[defaults setObject:[NSDecimalNumber zero] forKey:#"grossincome"];
[defaults synchronize];
grossIncome = (NSDecimalNumber *)[defaults objectForKey:#"grossincome"];
}
self.incomeValueTextField.enabled = NO;
self.incomeValueTextField.delegate = self;
self.incomeValueTextField.keyboardType = UIKeyboardTypeDecimalPad;
self.incomeValueTextField.text = [grossIncome getLocalizedCurrencyString];
And my complete category:
#import "NSDecimalNumber+Currency.h"
#import "Singletons.h"
#implementation NSDecimalNumber (Currency)
- (NSString *) getLocalizedCurrencyString
{
NSNumberFormatter *numberFormatter = [[Singletons sharedManager] numberFormatter];
NSString *numberString = [numberFormatter stringFromNumber:self];
return numberString;
}
- (NSString *) getLocalizedCurrencyStringWithDigits:(int)digits
{
if(digits == 2){
return [self getLocalizedCurrencyString];
}
NSNumberFormatter *numberFormatter;
if (digits == 0){
numberFormatter =[[Singletons sharedManager] numberFormatterNoDigits];
} else {
numberFormatter =[[NSNumberFormatter alloc] init];
[numberFormatter setNumberStyle:NSNumberFormatterDecimalStyle];
[numberFormatter setLocale:[NSLocale currentLocale]];
[numberFormatter setMinimumFractionDigits:digits];
[numberFormatter setMaximumFractionDigits:digits];
}
NSString *numberString = [numberFormatter stringFromNumber:self];
return numberString;
}
+ (NSDecimalNumber *) getUnLocalizedDecimalNumberWithString:(NSString *)currencyString
{
NSNumberFormatter *numberFormatter = [[Singletons sharedManager] numberFormatter];
NSNumber *formatedCurrency = [numberFormatter numberFromString:currencyString];
BOOL isDecimal = formatedCurrency != nil;
if(isDecimal){
return [NSDecimalNumber decimalNumberWithDecimal:[formatedCurrency decimalValue]];
} else {
return [NSDecimalNumber zero];
}
}
- (NSDecimalNumber *)abs {
if ([self compare:[NSDecimalNumber zero]] == NSOrderedAscending) {
// Number is negative. Multiply by -1
NSDecimalNumber * negativeOne = [NSDecimalNumber decimalNumberWithMantissa:1
exponent:0
isNegative:YES];
return [self decimalNumberByMultiplyingBy:negativeOne];
} else {
return self;
}
}
Yesterday you have been warned about subclassing/categories on class clusters, now you see why. (Okay, actually it's more or a problem with unexpected behaviour of NSUserDefaults, but it's related ^^)
Your problem is that the object you get from NSUserDefaults is not a NSDecimalNumber, because NSDecimalNumbers are not plist values that can be saved in NSUserDefaults. But NSDecimalNumber is a subclass of NSNumber, which can be saved in NSUserDefaults, so NSUserDefaults will only save the "NSNumber part" of the NSDecimalNumber, basically it converts it to a NSNumber. Through this process it loses its precision and it's class.
When you get the object from NSUserDefaults you will actually get an instance of NSNumber. And your category does not exist on NSNumber.
I added some debug log to your code and ran it for you:
// Wrong!
NSDecimalNumber *decimalNumber = [NSDecimalNumber decimalNumberWithString:#"1.23456789123456789"];
NSLog(#"%# - %#", decimalNumber, NSStringFromClass([decimalNumber class]));
[[NSUserDefaults standardUserDefaults] setObject:decimalNumber forKey:#"___number"];
NSDecimalNumber *objectFromUserDefaults = [[NSUserDefaults standardUserDefaults] objectForKey:#"___number"];
NSLog(#"%# - %#", objectFromUserDefaults, NSStringFromClass([objectFromUserDefaults class]));
Which yields this result:
xxx[98912:70b] 1.23456789123456789 - NSDecimalNumber
xxx[98912:70b] 1.234567891234568 - __NSCFNumber
As you can see the returned object is an instance of __NSCFNumber
Here is the correct way:
// Correct
NSDecimalNumber *decimalNumber = [NSDecimalNumber decimalNumberWithString:#"1.23456789123456789"];
NSLog(#"%# - %#", decimalNumber, NSStringFromClass([decimalNumber class]));
NSData *archivedDecimalNumber = [NSKeyedArchiver archivedDataWithRootObject:decimalNumber];
[[NSUserDefaults standardUserDefaults] setObject:archivedDecimalNumber forKey:#"___archivedNumber"];
NSData *dataFromUserDefaults = [[NSUserDefaults standardUserDefaults] objectForKey:#"___archivedNumber"];
NSDecimalNumber *decimalNumberFromUserDefaults = [NSKeyedUnarchiver unarchiveObjectWithData:dataFromUserDefaults];
NSLog(#"%# - %#", decimalNumberFromUserDefaults, NSStringFromClass([decimalNumberFromUserDefaults class]));
which yields:
xxx[98912:70b] 1.23456789123456789 - NSDecimalNumber
xxx[98912:70b] 1.23456789123456789 - NSDecimalNumber
as expected.
BUT you should still get rid of that NSDecimalNumber category. Just put that code into it's own class. Call it ZHNumberFormatter and do your formatting in there.
NSNumberFormatters take their time during creation, you don't want to create them for every single conversion.
Reset your simulator and try to run the app.
iOS Simulator --> Reset content and settings.
User NSKeyedArchiver and NSKeyedUnarchiver to store the object in user defaults.
Try to use below code its working fine.
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSDecimalNumber *grossIncome = [defaults objectForKey:#"grossincome"];
if (!grossIncome) {
NSDecimalNumber *decNum = [[NSDecimalNumber alloc] initWithDouble:0.0f];
NSData *myEncodedObject = [NSKeyedArchiver archivedDataWithRootObject:decNum];
[defaults setObject:myEncodedObject forKey:#"grossincome"];
[defaults synchronize];
NSData *myDecodedObject = [defaults objectForKey:#"grossincome"];
grossIncome = (NSDecimalNumber*)[NSKeyedUnarchiver unarchiveObjectWithData:myDecodedObject];
}
[grossIncome getLocalizedCurrencyString];
You probably still refer to the category somewhere.
You should create an exception Breakpoint. (look for "create exception Breakpoint" in the help menu)
This will stop you on the guilty line of code!

Resources