I am getting the following error please help me with a solution. My xcode gets aborted with the following error
Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[NSMutableArray objectAtIndex:]: index 0 beyond bounds for empty array'
*** Call stack at first throw:
(
0 CoreFoundation 0x0140a5a9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x0155e313 objc_exception_throw + 44
2 CoreFoundation 0x014000a5 -[__NSArrayM objectAtIndex:] + 261
3 UMMCelebrity 0x00043903 -[UMMFlickrView photoGallery:urlForPhotoSize:atIndex:] + 115
4 UMMCelebrity 0x0004a9d6 -[FGalleryViewController createGalleryPhotoForIndex:] + 422
5 UMMCelebrity 0x0004a5ac -[FGalleryViewController loadThumbnailImageWithIndex:] + 172
6 UMMCelebrity 0x0004a189 -[FGalleryViewController preloadThumbnailImages] + 281
7 UMMCelebrity 0x00046f84 -[FGalleryViewController loadView] + 2132
8 UIKit 0x0029d00e -[UIViewController view] + 56
9 UMMCelebrity 0x00043050 -[UMMFlickrView pushphotoview] + 192
10 UMMCelebrity 0x000446c6 -[UMMFlickrView connection:didReceiveData:] + 2230
11 Foundation 0x00996835 _NSURLConnectionDidReceiveData + 159
12 CFNetwork 0x033bde72 _ZN19URLConnectionClient21_clientDidReceiveDataEPK8__CFDataPNS_26ClientConnectionEventQueueE + 262
13 CFNetwork 0x0348a6b3 _ZN19URLConnectionClient26ClientConnectionEventQueue33processAllEventsAndConsumePayloadEP20XConnectionEventInfoI12XClientEvent18XClientEventParamsEl + 247
14 CFNetwork 0x0348a9cf _ZN19URLConnectionClient26ClientConnectionEventQueue33processAllEventsAndConsumePayloadEP20XConnectionEventInfoI12XClientEvent18XClientEventParamsEl + 1043
15 CFNetwork 0x033b5c80 _ZN19URLConnectionClient13processEventsEv + 100
16 CFNetwork 0x033b5acf _ZN17MultiplexerSource7performEv + 251
17 CoreFoundation 0x013eb8ff __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
18 CoreFoundation 0x0134988b __CFRunLoopDoSources0 + 571
19 CoreFoundation 0x01348d86 __CFRunLoopRun + 470
20 CoreFoundation 0x01348840 CFRunLoopRunSpecific + 208
21 CoreFoundation 0x01348761 CFRunLoopRunInMode + 97
22 GraphicsServices 0x018e21c4 GSEventRunModal + 217
23 GraphicsServices 0x018e2289 GSEventRun + 115
24 UIKit 0x001fbc93 UIApplicationMain + 1160
25 UMMCelebrity 0x00001d29 main + 121
26 UMMCelebrity 0x00001ca5 start + 53
)
terminate called after throwing an instance of 'NSException'
You're calling objectAtIndex: with the argument 0 on an empty NSMutableArray.
[NSMutableArray objectAtIndex:]: index 0 beyond bounds for empty array
If you know the NSMutableArray can be empty, you should consider calling count on it to see if it does indeed contain any elements, before trying to access the elements.
Obviously, there's an empty NSMutableArray in -[UMMFlickrView photoGallery:urlForPhotoSize:atIndex:] and you sent it objectAtIndex: with argument 0.
That means your NSMutableArray is empty. I think you didn't allocate the memory for NSMutableArray. Read this link, it may be helpful for you.
http://www.roseindia.net/answers/viewqa/Mobile-Applications/14614-NSMutableArray-Example-Code.html
May be on the 4th click nothing is pushed into the array, I'm not sure as I have no idea what you are trying to do.If you can add the code line that adds the object into your array, we could help you.
This error is occurring because the array is empty for sure.
Related
I have a NSMutableArray called rawData of size 198792. Each index contains an NSObject called DataSet. The interface for a DataSet is as follows:
#interface DataSet : NSObject {
NSNumber *rightFoot;
NSNumber *leftFoot;
}
I am trying to trim down the rawData using the following line of code:
[rawData removeObjectsInRange:NSMakeRange(0, StartTime*freq-1)];
where StartTime*freq-1 = 11799.
I am getting an error during runtime:
* Terminating app due to uncaught exception 'NSRangeException', reason: '* -[NSMutableArray objectAtIndex:]: index 198791 beyond bounds [0 .. 186992]'
Thank you for any help!
EDIT: stack trace
2012-02-16 17:59:31.671 fwd_analysis[8154:207] *** Terminating app due to uncaught
exception 'NSRangeException', reason: '*** -[NSMutableArray objectAtIndex:]: index
198791 beyond bounds [0 .. 186992]'
*** Call stack at first throw:
(
0 CoreFoundation 0x00dc25a9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x00f16313 objc_exception_throw + 44
2 CoreFoundation 0x00db80a5 -[__NSArrayM objectAtIndex:] + 261
3 fwd_analysis 0x00002a99 -[fwd_analysisViewController startButtonPressed:] + 252
4 UIKit 0x002b24fd -[UIApplication sendAction:to:from:forEvent:] + 119
5 UIKit 0x00342799 -[UIControl sendAction:to:forEvent:] + 67
6 UIKit 0x00344c2b -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 527
7 UIKit 0x003437d8 -[UIControl touchesEnded:withEvent:] + 458
8 UIKit 0x002d6ded -[UIWindow _sendTouchesForEvent:] + 567
9 UIKit 0x002b7c37 -[UIApplication sendEvent:] + 447
10 UIKit 0x002bcf2e _UIApplicationHandleEvent + 7576
11 GraphicsServices 0x0171a992 PurpleEventCallback + 1550
12 CoreFoundation 0x00da3944 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52
13 CoreFoundation 0x00d03cf7 __CFRunLoopDoSource1 + 215
14 CoreFoundation 0x00d00f83 __CFRunLoopRun + 979
15 CoreFoundation 0x00d00840 CFRunLoopRunSpecific + 208
16 CoreFoundation 0x00d00761 CFRunLoopRunInMode + 97
17 GraphicsServices 0x017191c4 GSEventRunModal + 217
18 GraphicsServices 0x01719289 GSEventRun + 115
19 UIKit 0x002c0c93 UIApplicationMain + 1160
20 fwd_analysis 0x00002758 main + 102
21 fwd_analysis 0x000026e9 start + 53
)
terminate called after throwing an instance of 'NSException'
Current language: auto; currently objective-c
Program received signal: “SIGABRT”.
Your array can't be the size you think it is.
Look at the error message: index beyond bounds [0 .. 186992]. Therefore the size of your array is actually 186993.
I would also recommend you log the value of StartTime*freq-1 at runtime, and compare it with the length of your array.
Also, something that could cause issues here is that it's a mutable array, and you're removing stuff from it, so the length will change at runtime. This is why I recommend logging both the length and range at the point where the code breaks.
So, something like this:
NSLog(#"Length: %i",[rawData length]);
NSLog(#"Range: %i",StartTime*freq-1);
[rawData removeObjectsInRange:NSMakeRange(0, StartTime*freq-1)];
Update: how to add objects to another array instead of deleting from the current one.
You need to use this method to get an array which contains objects in a certain range:
- (NSArray *)subarrayWithRange:(NSRange)range
You can then add these objects into another array, for example:
// before you did this:
[rawData removeObjectsInRange:NSMakeRange(0, StartTime*freq-1)];
// to create a filtered array do:
NSArray *filtered = [rawData subarrayWithRange:NSMakeRange(0, StartTime*freq-1)];
*** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[NSMutableArray objectAtIndex:]: index 18 beyond bounds [0 .. 16]'
*** Call stack at first throw:
(
0 CoreFoundation 0x02b11b99 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x02c6140e objc_exception_throw + 47
2 CoreFoundation 0x02b07695 -[__NSArrayM objectAtIndex:] + 261
3 MyPocket 0x0005efe9 -[loginLocalitems tableView:didSelectRowAtIndexPath:] + 638
4 UIKit 0x00be9a48 -[UITableView _selectRowAtIndexPath:animated:scrollPosition:notifyDelegate:] + 1140
5 UIKit 0x00be032e -[UITableView _userSelectRowAtIndexPath:] + 219
6 Foundation 0x0037821a __NSFireDelayedPerform + 441
7 CoreFoundation 0x02af2f73 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 19
8 CoreFoundation 0x02af45b4 __CFRunLoopDoTimer + 1364
9 CoreFoundation 0x02a50dd9 __CFRunLoopRun + 1817
10 CoreFoundation 0x02a50350 CFRunLoopRunSpecific + 208
11 CoreFoundation 0x02a50271 CFRunLoopRunInMode + 97
12 GraphicsServices 0x03f4e00c GSEventRunModal + 217
13 GraphicsServices 0x03f4e0d1 GSEventRun + 115
14 UIKit 0x00b84af2 UIApplicationMain + 1160
15 MyPocket 0x000023d2 main + 84
16 MyPocket 0x00002375 start + 53
17 ??? 0x00000001 0x0 + 1
)
terminate called after throwing an instance of 'NSException'
What is the reason for the above array. This crash appears only when i select the lower cells of table view Anyone pls help
This error is telling you that your NSMutableArray has only from 0 to 16 objects inside. When you scroll to the bottom of the table and select the lower cell you are trying to access an object in the array at index higher then 16. So try to check if the array that you are using for the table is properly filled, and that you are not removing something from it at later time.
you are loading data from a mutable array?
check if the array really has 18 elements.
or if you are giving a number bigger than the actual row count in the numberOfRows inSection method
this is a range exception:
index 18 beyond bounds [0 .. 16]
as you see, it only occurs when you click the lower items
When I search on TableView through TextDidChange which calls handleSearchTerm subroutine, it perfectly works. However, I removed TextDidChange and use SearchButtonClicked to update tableView (use same subroutine),it doesn't update TableView properly and crash when scroll(out of bound index in cellForRowAtIndex) even though datasource has been changed in subroutine. Any idea?
[78515:207] *** Terminating app due to uncaught exception 'NSRangeException', reason: '-[__NSCFArray objectAtIndex:]: index (8) beyond bounds (8)'
*** Call stack at first throw:
(
0 CoreFoundation 0x00db8be9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x00f0d5c2 objc_exception_throw + 47
2 CoreFoundation 0x00d71628 +[NSException raise:format:arguments:] + 136
3 CoreFoundation 0x00d7159a +[NSException raise:format:] + 58
4 CoreFoundation 0x00dae8c9 _NSArrayRaiseBoundException + 121
5 CoreFoundation 0x00db0027 -[__NSCFArray objectAtIndex:] + 87
6 DrinkGuide_v1.0 0x00005d6c -[AllDrinkTableViewController tableView:cellForRowAtIndexPath:] + 371
7 UIKit 0x003357fa -[UITableView(UITableViewInternal) _createPreparedCellForGlobalRow:withIndexPath:] + 634
8 UIKit 0x0032b77f -[UITableView(UITableViewInternal) _createPreparedCellForGlobalRow:] + 75
9 UIKit 0x00340450 -[UITableView(_UITableViewPrivate) _updateVisibleCellsNow:] + 1561
10 UIKit 0x00338538 -[UITableView layoutSubviews] + 242
11 QuartzCore 0x01c76451 -[CALayer layoutSublayers] + 181
12 QuartzCore 0x01c7617c CALayerLayoutIfNeeded + 220
13 QuartzCore 0x01c6f37c _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 310
14 QuartzCore 0x01c6f0d0 _ZN2CA11Transaction6commitEv + 292
15 QuartzCore 0x01c9f7d5 _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 99
16 CoreFoundation 0x00d99fbb __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 27
17 CoreFoundation 0x00d2f0e7 __CFRunLoopDoObservers + 295
18 CoreFoundation 0x00cf7bd7 __CFRunLoopRun + 1575
19 CoreFoundation 0x00cf7240 CFRunLoopRunSpecific + 208
20 CoreFoundation 0x00cf7161 CFRunLoopRunInMode + 97
21 GraphicsServices 0x016ed268 GSEventRunModal + 217
22 GraphicsServices 0x016ed32d GSEventRun + 115
23 UIKit 0x002d042e UIApplicationMain + 1160
24 DrinkGuide_v1.0 0x0000298c main + 102
25 DrinkGuide_v1.0 0x0000291d start + 53
)
terminate called after throwing an instance of 'NSException'
I think crash is caused by cellForRowAtIndexPath, can you please post code for following methods :
cellForRowAtIndexPath
SearchButtonClicked
yourSubroutine you are calling
also mention your array or collection from which you are loading your table.
Thanks,
as per your crash log it seems you are retuning wrong no of cells in you noOfcellsInsection method. You are getting array out of bounds error.When you are doing search make a flag true and according to that flag return no of rows for the table view using your filtered array's count.
I am developing an iPad application with SDK4.2. I have a very strange error when touching any textField in my application. The first time I touch, the keyboard is shown, but when a second touch is done in the object I obtain following trace.
And it occurs also in any TextField shown in a HTML page with a UIWebView object.
Any ideas?
I am really confused with this.. Thanks in advance!
2010-12-17 11:53:11.697 BancoPopular[48914:207] *** Assertion failure in -[UIButtonLabel setTextColor:], /SourceCache/UIKit_Sim/UIKit-1447.6.4/UILabel.m:314
2010-12-17 11:53:11.699 BancoPopular[48914:207] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid parameter not satisfying: color'
*** Call stack at first throw:
(
0 CoreFoundation 0x01730be9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x018855c2 objc_exception_throw + 47
2 CoreFoundation 0x016e9628 +[NSException raise:format:arguments:] + 136
3 Foundation 0x0013947b -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 116
4 UIKit 0x0045d1dc -[UILabel setTextColor:] + 164
5 UIKit 0x0052177b -[UIButton layoutSubviews] + 1337
6 UIKit 0x005f3420 -[UICalloutBarButton layoutSubviews] + 54
7 QuartzCore 0x011a4451 -[CALayer layoutSublayers] + 181
8 QuartzCore 0x011a417c CALayerLayoutIfNeeded + 220
9 QuartzCore 0x011a4088 -[CALayer layoutIfNeeded] + 111
10 UIKit 0x0051f2ff -[UIButton titleLabel] + 81
11 UIKit 0x005f81d1 -[UICalloutBarButton setContentScale:] + 141
12 UIKit 0x005f6c5d -[UICalloutBar _updateVisibleItems] + 2240
13 UIKit 0x005f2970 -[UICalloutBar appear] + 211
14 UIKit 0x005eaaa9 -[UITextSelectionView showCommandsWithReplacements:] + 291
15 Foundation 0x000bd7f6 __NSFireDelayedPerform + 441
16 CoreFoundation 0x01711fe3 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 19
17 CoreFoundation 0x01713594 __CFRunLoopDoTimer + 1220
18 CoreFoundation 0x0166fcc9 __CFRunLoopRun + 1817
19 CoreFoundation 0x0166f240 CFRunLoopRunSpecific + 208
20 CoreFoundation 0x0166f161 CFRunLoopRunInMode + 97
21 GraphicsServices 0x01e25268 GSEventRunModal + 217
22 GraphicsServices 0x01e2532d GSEventRun + 115
23 UIKit 0x0034d42e UIApplicationMain + 1160
24 BancoPopular 0x0000292e main + 84
25 BancoPopular 0x000028d1 start + 53
26 ??? 0x00000001 0x0 + 1
)
terminate called after throwing an instance of 'NSException'
Look carefully what exception was about. It said "reason: 'Invalid parameter not satisfying: color'", somewhere in your code, you provide wrong parameter that is supposed to be valid colors. Apparently, it seems like you use UIButton with label and set its color but not valid.
My guess is that you have some object going away somewhere, and that object contains the "color" value.
Most likely you received an autoreleased value from some call and did not retain it, so it went "poof" when the UI came up for air.
I'm used to Java programming where an error is thrown and it tells you at what line the error was thrown from which file. But with Objective-C in XCode, I can't ever tell where the error comes from. How can I figure out where the error came from? Here is an example of a crash error:
2011-01-04 10:36:31.645 TestGA[69958:207] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[NSMutableArray objectAtIndex:]: index 0 beyond bounds for empty array'
*** Call stack at first throw:
(
0 CoreFoundation 0x01121be9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x012765c2 objc_exception_throw + 47
2 CoreFoundation 0x011176e5 -[__NSArrayM objectAtIndex:] + 261
3 TestGA 0x000548d8 -[S7GraphView drawRect:] + 5763
4 UIKit 0x003e16eb -[UIView(CALayerDelegate) drawLayer:inContext:] + 426
5 QuartzCore 0x00ec89e9 -[CALayer drawInContext:] + 143
6 QuartzCore 0x00ec85ef _ZL16backing_callbackP9CGContextPv + 85
7 QuartzCore 0x00ec7dea CABackingStoreUpdate + 2246
8 QuartzCore 0x00ec7134 -[CALayer _display] + 1085
9 QuartzCore 0x00ec6be4 CALayerDisplayIfNeeded + 231
10 QuartzCore 0x00eb938b _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 325
11 QuartzCore 0x00eb90d0 _ZN2CA11Transaction6commitEv + 292
12 QuartzCore 0x00ee97d5 _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 99
13 CoreFoundation 0x01102fbb __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 27
14 CoreFoundation 0x010980e7 __CFRunLoopDoObservers + 295
15 CoreFoundation 0x01060bd7 __CFRunLoopRun + 1575
16 CoreFoundation 0x01060240 CFRunLoopRunSpecific + 208
17 CoreFoundation 0x01060161 CFRunLoopRunInMode + 97
18 GraphicsServices 0x01932268 GSEventRunModal + 217
19 GraphicsServices 0x0193232d GSEventRun + 115
20 UIKit 0x003b842e UIApplicationMain + 1160
21 TestGA 0x00001cd8 main + 102
22 TestGA 0x00001c69 start + 53
23 ??? 0x00000001 0x0 + 1
So from looking at this, where is the error coming from and from which class is it coming from?
2 CoreFoundation 0x011176e5 -[__NSArrayM objectAtIndex:] + 261
An array you are using with that method is out of range.. In this case the array is empty and you try to get a value from a point that doesn't exist..
But i agree with you that it is pretty hard to find.. If you use the [white and yellow]-button next to the button you use to open the console you can check the debugger.. This way you can click on the " 2 CoreFoundation 0x011176e5 -[__NSArrayM objectAtIndex:] + 261" and see where it goes wrong..
It might be a good idea to refer to the Xcode debugging guide at Apple.com to learn more about how to debug your iOS applications.