I have some error in my app,
It report in console:
exc:*** -[__NSArrayI objectAtIndex:]: index 0 beyond bounds for empty array
but it just crashed and terminated, just didn't break on the crash line of code.
Is it a bug or something wrong on my settings ?
I know what is the problem of my code. I just want to know why xcode not break at the line of the code, not just terminated the app running.
Xcode 6.1 Mac OSX 10.10
somewhere in your code, you are trying to access objects within an array but the array is empty. Before accessing elements of array, just check if array is empty or not by using [myArray count].
Related
I try to update my project to Swift 3 and my app crash just after launching Xcode display the following message:
thread 1 EXC_BREAKPOINT (code=1, subcode=0x101959bfc)
here's the line where the problem happened
var list:[PFObject]! = []
(...)
let x = list[indexPath.row - 1]
let text:Int = (x["text"] as! NSArray)[0] as! Int //The line where the error is displayed
The console only said that:
(lldb)
I've removed all the breakpoints from the breakpoints navigator with no result, the issue happened both on device and on simulator. (I use Xcode 8.2)
Thanks a lot for your help
Take a look at the stack trace printed right before (lldb), and break down that statement in smaller pieces if is still hard to understand where the error actually is.
Considering the line the pointer is at, it could be that x["text"] is not an array, that the array is empty, or that the element is not an int.
In other words, those force unwrap could fail or the array could be empty.
I've been trying to figure out how this innocent line could crash the app. The same code works on 64-bit simulators (iPhone 5s or later) but would crash on 32-bit simulators whenever new_or_used (an optional String in an NSManagedObject) is accessed. The stack trace does not seem helpful.
Any insights appreciated. Thanks!
According to your image seems the compiler try to use an already deallocated String.
To avoid your crash, try to correct your code as :
if let newOrUsed = itemPriceGuide.new_or_used as? String {
// do your stuff
}
This happened again just recently, and it was due to the variable starting with "new". NSPersistentStoreCoordinator throws EXC_BAD_ACCESS when deallocating an NSManagedObject after reading a specific NSManagedProperty
I am having an issue where a crash only occurs when the application is installed via HockeyApp, not via Xcode.
This is the report I get from HockeyApp:
*** Terminating app due to uncaught exception 'NSRangeException', reason: '-[__NSCFArray objectAtIndex:]: index (-1970199490 (or possibly larger)) beyond bounds (15)'
MainViewController.m, line 646
Which refers to this line:
for (int i; i < [resultsArray count]; i++) {
if ([[resultsArray[i] valueForKey:#"uniqueId"] isEqualToString:[[NSUserDefaults standardUserDefaults]
stringForKey:#"FbId"]]) {
resultsArray = resultsArray[i];
}
}
Any ideas why I would be getting a crash there when a build is installed via HockeyApp but not via Xcode? I've even tried building the app to a device using both development and distribution certs, but both work fine as long as the build isn't installed via HockeyApp.
I think the issue would be not initializing the value of the i in the for loop.
it should be for (int i=0;....
if it is not initialised, then the value of i would be unpredictable, it could be either null or it could be the value of its memory address.
if you didn't initialise it, then there will be infinite loop (if there is no crash) here as the value of i will be some random negative number -1970199490,
Also even if you do it from xcode, it results in the same behaviour.
I have a Ruby on Rails application that has an API, it's an OAuth 2.0 provider and uses Doorkeeper. I am creating an iPhone client for that application and am using the gtm-oauth2 library for authentication. Here is the Github repository for the iPhone app.
I manage do the authentication request using the library and get the response from the OAuth server, but (I think that) when the iPhone app receives the response, the iPhone app crashes. I get the following error:
2013-03-25 07:30:51.563 Catapult for iOS[68917:c07] -[NSNull length]: unrecognized selector sent to instance 0x14f2678
2013-03-25 07:30:51.564 Catapult for iOS[68917:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSNull length]: unrecognized selector sent to instance 0x14f2678'
*** First throw call stack:
(0x13c1012 0x11e6e7e 0x144c4bd 0x13b0bbc 0x13b094e 0xf074 0x185e3 0x13b51bd 0x13b50d6 0x1531a 0x1512b 0x14ae2 0x13b51bd 0x13b50d6 0x11d0a 0x1032a 0x13b51bd 0x13b50d6 0x79be 0x77ed 0x8cf2 0xcec589 0xcea652 0xceb89a 0xcea60d 0xcea785 0xc37a68 0x4a2a911 0x4a29bb3 0x4a67cda 0x13638fd 0x4a6835c 0x4a682d5 0x4952250 0x1344f3f 0x1344a39 0x1367734 0x1366f44 0x1366e1b 0x22be7e3 0x22be668 0x12affc 0x2c6d 0x2b95)
libc++abi.dylib: terminate called throwing an exception
I am a complete noob/beginner when it comes to iOS development and Objective-C programming, and I am learning how to create my first app using this little project. I asked the same question in the gtm-oaut2 Google Group and according to them, the problem comes from my code and not the library. The problem is that all of my code is taken from their wiki and I can't pinpoint where the app crashes. If I understand correctly, at some point I am calling length of NSNull, but I am not calling length anywhere, hence my confusion. Also, when the app crashes, the line hilighted is in the main.m file and the error (on the right label, not in the output) is the following:
Thread 1: signal SIGABRT
I have no clue what that means...
Does anyone know what the problem might be please?
You're right that the issue is that somewhere you've got the length message being sent to an instance of NSNull. To pinpoint where exactly this is happening set a breakpoint on objc_exception_throw. You can do this in the Xcode UI with little "+" button in the bottom left corner on the breakpoints tab. Select "Add Exception breakpoint." Then the debugger will stop your program at the point where the error occurs instead of waiting for the program to actually crash.
Well... you understood the error correctly.. You are somewhere calling length on a NSNull instance.
I must find out where this is happening.
I think this is happening in a JSON response. Maybe you (or "the code") is calling length on something it expects its a NSString but it is instead NSNull (that is the json has a NULL value).
Try if you manage to print the json response and see if you found a key mapped to a null value...
NSNull does not respond to length
You can check the documentation for NSNull to see that this is the case.
Without having an idea of what your code base is doing I am not sure where to look, you must be calling [NSNull null]; at some point to get the NSNull object or you are using a framework somewhere that returns this.
After upgrading to XCode4 (v. 4.2, 4D199) it seems every time my apps crash while debugging, the debugging points to main(), and the stack is unsymbolicated and useless.
This has been working fine for years, I have no idea what has gone wrong.
I'm using GDB. I also tried the LLDB as per this advice, and it didn't work either (similar, useless stack).
My breakpoints work, I get the full stack, and can inspect variables when my code hits those.
Steps to reproduce:
NB. this happens with my own project, but I'll use Apple's code here to remove that variable from the equation
Download the following sample from Apple: https://developer.apple.com/library/ios/#samplecode/UICatalog/Introduction/Intro.html#//apple_ref/doc/uid/DTS40007710
In the ImagesViewController class, add the following code to the viewDidLoad method (so it will crash – we want it to crash for this test):
// please note: this code is designed to crash! I want it to crash, to highlight my issue with XCode.
NSMutableArray* test = [NSMutableArray new];
[test insertObject:NULL atIndex:0];
Then run the app & hit the 'Images' row.
It crashes with a message like:
2011-12-23 14:07:02.788 UICatalog[13394:707] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSArrayM insertObject:atIndex:]: object cannot be nil'
*** First throw call stack:
(0x37bbb8bf 0x316a11e5 0x37b1020f 0x699f 0x34fac7ff 0x34fb8c39 0x34fb8aa9 0x34fb898f 0x34fb815b 0x34fb7f53 0x34fac673 0x34fac349 0x66c1 0x35026565 0x3509ece7 0x31aec943 0x37b8fa63 0x37b8f6c9 0x37b8e29f 0x37b114dd 0x37b113a5 0x3768ffcd 0x34fa1743 0x2459 0x2418)
terminate called throwing an exception(gdb)
View in xcode:
Thanks to brigadir for pointing me to the solution!
It works well. Here's some screenshots for how to solve this for anyone finding my question:
Tap the plus button of the breakpoints tab
Then click Done