I am new to iphone developement, during development I face problem due to this error. I am unable to trace it that from where it is produced.
app due to uncaught exception 'NSRangeException', reason: '*** -[NSMutableArray objectAtIndex:]: index 5 beyond bounds [0 .. 4]'
*** Call stack at first throw:
(
0 CoreFoundation 0x012dcbe9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x014315c2 objc_exception_throw + 47
2 CoreFoundation 0x012d26e5 -[__NSArrayM objectAtIndex:] + 261
3 Dispatch 0x0002feeb -[ZoneFareTaxi parseMessage:] + 754
4 Dispatch 0x0002fbf0 -[ZoneFareTaxi initWithMessageString:] + 92
5 Dispatch 0x0003b949 -[ServerConnection onUdpSocket:didReceiveData:withTag:fromHost:port:] + 8862
6 Dispatch 0x0002350e -[AsyncUdpSocket maybeCompleteCurrentReceive] + 458
7 Dispatch 0x00023210 -[AsyncUdpSocket doReceive:] + 1364
8 Dispatch 0x00022c60 -[AsyncUdpSocket doReceive4] + 80
9 Dispatch 0x00022add -[AsyncUdpSocket maybeDequeueReceive] + 561
10 Foundation 0x000da7f6 __NSFireDelayedPerform + 441
11 CoreFoundation 0x012bdfe3 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 19
12 CoreFoundation 0x012bf594 __CFRunLoopDoTimer + 1220
13 CoreFoundation 0x0121bcc9 __CFRunLoopRun + 1817
14 CoreFoundation 0x0121b240 CFRunLoopRunSpecific + 208
15 CoreFoundation 0x0121b161 CFRunLoopRunInMode + 97
16 GraphicsServices 0x01a4d268 GSEventRunModal + 217
17 GraphicsServices 0x01a4d32d GSEventRun + 115
18 UIKit 0x0036a42e UIApplicationMain + 1160
19 Dispatch 0x000024b4 main + 102
20 Dispatch 0x00002445 start + 53
21 ??? 0x00000001 0x0 + 1
)
terminate called after throwing an instance of 'NSException'
This is likely an off by one error. Your NSMutableArray has only 5 elements and you are accessing the 6th object at index 5. Indexes are 0 based.
The problem resides likely in this method: [ZoneFareTaxi parseMessage:]
It should be in the parseMessage method implementation, of the class ZoneFareTaxi.
In that method you send the message objectAtIndex: to an NSMutableArray object, passing a value that in that case is 5 (presumably using a variable).
It says that you are accessing to the sixth element of the array, while it has only 5 elements. Arrays are 0 indexed.
this problem only appears only if your trying to access an element from array with index is greater than your count of array.
From this:
-[NSMutableArray objectAtIndex:]: index 5 beyond bounds [0 .. 4]
you can see that you're trying to access index 5 in an array that only goes from 0 to 4.
From this:
objc_exception_throw + 47
-[__NSArrayM objectAtIndex:] + 261
-[ZoneFareTaxi parseMessage:] + 754
you can see that the problem is happening in your [ZoneFareTaxi parseMessage:] method.
Related
Crash Report :
> Thread : Crashed: com.apple.main-thread 0 libobjc.A.dylib
> 0x306bdf46 objc_msgSend + 5 1 libAVFAudio.dylib
> 0x21ac3e71 -[AVAudioSession privateBeginInterruption] + 52 2
> Foundation 0x23bb8d6f __NSThreadPerformPerform +
> 386 3 CoreFoundation 0x22e70377
> __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 14 4 CoreFoundation 0x22e6f819 __CFRunLoopDoSources0 + 364
> 5 CoreFoundation 0x22e6dded __CFRunLoopRun + 772 6
> CoreFoundation 0x22dbc211 CFRunLoopRunSpecific + 476 7
> CoreFoundation 0x22dbc023 CFRunLoopRunInMode + 106 8
> GraphicsServices 0x2a16f0a9 GSEventRunModal + 136 9
> UIKit 0x263c81d1 UIApplicationMain + 1440 10
> HIIT GURU 0x000d7377 main (main.m:16)
I am getting this crash randomly. I tried to check each line of code but i couldn't find any solution. Please suggest something to solve this. I am getting this crash in ios8.1 only.
This often occurs when the reference to the receiving object gets invalid.
Start with a static analysis of your code. Most of the times you can let Xcode do it for you through the Product -> Analyze tool. Also try enabling zombie objects while debugging through editing the current scheme going through Product -> Scheme -> Edit Scheme and check the appropriate box in the Diagnostics tab. Once enabled you have to wait for the crash to occur again if you don't know how to reproduce.
For example, I get this error in debug area:
2014-05-01 05:01:28.052 MyApp[93187:303] *** setObjectForKey: object cannot be nil (key: -1)
2014-05-01 05:01:28.057 MyApp[93187:303] (
0 CoreFoundation 0x00007fff8cb3f25c __exceptionPreprocess + 172
1 libobjc.A.dylib 0x00007fff89202e75 objc_exception_throw + 43
2 CoreFoundation 0x00007fff8ca3a46e -[__NSDictionaryM setObject:forKey:] + 1102
3 MyApp 0x0000000100009725 +[SystemTools getData:] + 5509
4 MyApp 0x0000000100001c4b -[AppDelegate drawCanvas:] + 1467
5 MyApp 0x0000000100001675 -[AppDelegate repeatingTimer:] + 85
6 Foundation 0x00007fff8ec480f4 __NSFireTimer + 96
7 CoreFoundation 0x00007fff8caa6564 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 20
8 CoreFoundation 0x00007fff8caa609f __CFRunLoopDoTimer + 1151
9 CoreFoundation 0x00007fff8cb175aa __CFRunLoopDoTimers + 298
10 CoreFoundation 0x00007fff8ca618e5 __CFRunLoopRun + 1525
11 CoreFoundation 0x00007fff8ca610b5 CFRunLoopRunSpecific + 309
12 HIToolbox 0x00007fff875dca0d RunCurrentEventLoopInMode + 226
13 HIToolbox 0x00007fff875dc7b7 ReceiveNextEventCommon + 479
14 HIToolbox 0x00007fff875dc5bc _BlockUntilNextEventMatchingListInModeWithFilter + 65
15 AppKit 0x00007fff907853de _DPSNextEvent + 1434
16 AppKit 0x00007fff90784a2b -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] + 122
17 AppKit 0x00007fff90778b2c -[NSApplication run] + 553
18 AppKit 0x00007fff90763913 NSApplicationMain + 940
19 MyApp 0x0000000100016aa2 main + 34
20 libdyld.dylib 0x00007fff9440b5fd start + 1
21 ??? 0x0000000000000003 0x0 + 3
)
Unfortunately, I have saveral "setObject:forKey:" calls in "SystemTools getData:" function.
How can I determine to which call this error is related? What that numbers (after plus) means?
Add an Execption breakpoint in your break points. This will halt at the line of code which is causing the app to crash. That way you dont have to debug with NSLogs.
The default behavior of Xcode is to stop where the exception is
caught, not where the exception is raised!
To explain those lines in the crash logs:
From Ray Wenderlich's blog:
2 XYZLib 0x34648e88 0x83000 + 8740
It is basically four columns:
The frame number – in this case, 2.
The name of the binary – in this case, XYZLib.
The address of the function that was called – in this case, 0x34648e88.
The fourth column is divided into two sub-columns, a base address and an offset. Here it is 0×83000 + 8740, where the first number points to the file, and the second points to the line of code in that file.
Use breakpoints in all of your setObject:forKey calls. Use NSLog for print some useful information in log. You are a developer so you need to know debugging also.
The first line of the output is useful here:
setObjectForKey: object cannot be nil (key: -1)
The NSDictionary doesn't like nil values, so look for a place in your getData method that could be assigning a nil value to a key of "-1".
Good luck!
we use flurry (advertisement and analytics) in our application. Since some time the application simple crashes after it was used on this phone and we start it again.
The complete error log:
Flurry: Starting session on Agent Version [Flurry_iOS_123_4.3.2]
2014-04-29 12:48:24.875 <ProjectName> 2.0[62373:1303] -[NSNull length]: unrecognized selector sent to instance 0x5a8068
2014-04-29 12:48:24.879 <ProjectName> 2.0[62373:1303] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSNull length]: unrecognized selector sent to instance 0x5a8068'
*** First throw call stack:
(
0 CoreFoundation 0x0045c1e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x02e748e5 objc_exception_throw + 44
2 CoreFoundation 0x004f9243 -[NSObject(NSObject) doesNotRecognizeSelector:] + 275
3 CoreFoundation 0x0044c50b ___forwarding___ + 1019
4 CoreFoundation 0x0044c0ee _CF_forwarding_prep_0 + 14
5 <ProjectName> 2.0 0x00128722 +[FlurryProtocolData limitStringLength:] + 35
6 <ProjectName> 2.0 0x001289ae +[FlurryProtocolData appendString:toData:] + 46
7 <ProjectName> 2.0 0x0012d1f2 -[FlurrySession data] + 1398
8 <ProjectName> 2.0 0x0012c3a7 +[FlurrySession addToSavedSessions:] + 148
9 <ProjectName> 2.0 0x00128e65 +[FlurrySession sessionWithApiKey:startTime:] + 472
10 <ProjectName> 2.0 0x00139fc4 __29-[FlurryImpl setupForApiKey:]_block_invoke + 291
11 libdispatch.dylib 0x03a1d7b8 _dispatch_call_block_and_release + 15
12 libdispatch.dylib 0x03a324d0 _dispatch_client_callout + 14
13 libdispatch.dylib 0x03a20047 _dispatch_queue_drain + 452
14 libdispatch.dylib 0x03a1fe42 _dispatch_queue_invoke + 128
15 libdispatch.dylib 0x03a20de2 _dispatch_root_queue_drain + 78
16 libdispatch.dylib 0x03a21127 _dispatch_worker_thread2 + 39
17 libsystem_pthread.dylib 0x03d61dab _pthread_wqthread + 336
18 libsystem_pthread.dylib 0x03d65cce start_wqthread + 30
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
(username, project name and other privacy related parts have been replaced)
My code:
- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions
{
...
[Flurry startSession:#"<API-CODE>"];
...
return YES;
}
Edit 1:
I checked that the variable with the API-Key is really set and removed it even with a fixed value and I still get the same problem. Commenting the line of Flurry fixes the crash.
Edit 2:
The problem only appears after I already tracked some events with Flurry. So if I kill the application then and restart it, I get this error message. If I uninstall the application and reinstall it later, the error has gone. So it seems to be something within the saved state of Flurry.
It actually was because I transmitted an integer as user-id to flurry. But they only support strings for that. So please change your parameters accordingly.
I only replace the video files in my existing code, but if i replace all the video files my application will crash in iphone. it is an universal application but Ipad support all the new video files and crash on iphone. the following warning occur:
[NSCFType setLength:]: unrecognized selector sent to instance
0x19d790 2012-02-29 15:13:49.932[584:307] * Terminating app due to
uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFType
setLength:]: unrecognized selector sent to instance 0x19d790'
* Call stack at first throw: ( 0 CoreFoundation 0x3759dc7b __exceptionPreprocess + 114 1 libobjc.A.dylib
0x32d9bee8 objc_exception_throw + 40 2 CoreFoundation
0x3759f3e3 -[NSObject(NSObject) doesNotRecognizeSelector:] + 98 3
CoreFoundation 0x37544467 __forwarding + 506
4 CoreFoundation 0x37544220
_CF_forwarding_prep_0 + 48 5 Visionaries 0x00005179 -[Visionaries_ViewController
connection:didReceiveResponse:] + 56 6 Foundation
0x35183cd5 -[NSURLConnection(NSURLConnectionReallyInternal)
sendDidReceiveResponse:] + 92 7 Foundation
0x35183c3b _NSURLConnectionDidReceiveResponse + 86 8 CFNetwork
0x302941b4
_ZN19URLConnectionClient29_clientSendDidReceiveResponseEP14_CFURLResponsePNS_26ClientConnectionEventQueueE
+ 64 9 CFNetwork 0x30284bc8 _ZN19URLConnectionClient26ClientConnectionEventQueue33processAllEventsAndConsumePayloadEP20XConnectionEventInfoI12XClientEvent18XClientEventParamsEl
+ 332 10 CFNetwork 0x30284d84 _ZN19URLConnectionClient26ClientConnectionEventQueue33processAllEventsAndConsumePayloadEP20XConnectionEventInfoI12XClientEvent18XClientEventParamsEl
+ 776 11 CFNetwork 0x30284984 _ZN19URLConnectionClient13processEventsEv + 100 12 CFNetwork 0x3028484c _ZN17MultiplexerSource7performEv + 192 13 CFNetwork
0x30284788 _ZN17MultiplexerSource8_performEPv + 12 14 CoreFoundation
0x375518d1 CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION
+ 14 15 CoreFoundation 0x37521ecd __CFRunLoopDoSources0 + 384 16 CoreFoundation 0x375216f9 __CFRunLoopRun + 264 17 CoreFoundation
0x3752150b CFRunLoopRunSpecific + 226 18 CoreFoundation
0x37521419 CFRunLoopRunInMode + 60 19 GraphicsServices
0x33e76d24 GSEventRunModal + 196 20 UIKit
0x3591d57c -[UIApplication _run] + 588 21 UIKit
0x3591a558 UIApplicationMain + 972 22 Visionaries
0x00002391 main + 80 23 Visionaries
0x0000233c start + 40 ) terminate called after throwing an instance of
'NSException'
Somebody has an idea, please help.
By the crash log we see that, inside -[Visionaries_ViewController connection:didReceiveResponse:], you are calling the method setLength: on an object that does not have that method.
Can be a memory or logic problem. Please provide more info.
I am using xcode Instruments to track Allocations and Leaks. My app is crashing though. It does not crash when running the regular debug or release builds standalone, only when under Instruments:
Any thoughts ideas very gratefully received....
Exception Type: EXC_BAD_ACCESS (SIGBUS)
Exception Codes: KERN_PROTECTION_FAILURE at 0x0002b2e0
Crashed Thread: 0
Thread 0 name: Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0 libobjc.A.dylib 0x34499c96 objc_msgSend + 14
1 ZZZ Test Suite 0x000a3d74 0x95000 + 60788
2 CoreFoundation 0x308e4c3c -[NSObject(NSObject) release] + 24
3 CoreFoundation 0x308e519a CFRelease + 62
4 CoreFoundation 0x308e7eb4 _CFAutoreleasePoolPop + 140
5 Foundation 0x341b41c4 -[NSAutoreleasePool release] + 92
6 UIKit 0x309e5f08 _UIApplicationHandleEvent + 5784
7 GraphicsServices 0x30269e70 PurpleEventCallback + 660
8 CoreFoundation 0x30957a90 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 20
9 CoreFoundation 0x30959838 __CFRunLoopDoSource1 + 160
10 CoreFoundation 0x3095a606 __CFRunLoopRun + 514
11 CoreFoundation 0x308eaebc CFRunLoopRunSpecific + 224
12 CoreFoundation 0x308eadc4 CFRunLoopRunInMode + 52
13 GraphicsServices 0x30269418 GSEventRunModal + 108
14 GraphicsServices 0x302694c4 GSEventRun + 56
15 UIKit 0x30a10d62 -[UIApplication _run] + 398
16 UIKit 0x30a0e800 UIApplicationMain + 664
17 ZZZ Test Suite 0x0009665c 0x95000 + 5724
18 ZZZ Test Suite 0x00096604 0x95000 + 5636
Try running it through the analyser first. You can run it from xcode from the |product| menu then select Analyze. It's a static analyser (clang) that analyses your code when it builds so any problems causing your code to crash at runtime could well be visible through static analysis. Give it a try and fix any problems it throws up then try instruments again.
As a complement to what Ian says above:
set the Environment variable "NSZombieEnabled" to YES
and you will hopefully have a more informative fail.
(In XCode 4 the Environment Variables is found under "Edit Scheme" and select "Debug")