How to find where exactly did -[NSNull length]: unrecognized selector sent to instance happen i mean the line number.
Asked
Active
Viewed 7,619 times
0
-
1I assume you talk to a REST-API and get back JSON and assign the contents of one of the elements within the JSON to a string without checking whether the string is actually valid. You should check if the element from the JSON is `NSNull` and if so assign nil. – dasdom Jul 14 '14 at 14:09
-
3You probably have an array of different type objects and were expecting them to be `NSString` objects only, however some are `NSNull` objects. I wouldn't be surprised to hear you got the array from a JSON response. – trojanfoe Jul 14 '14 at 14:09
-
1@trojanfoe I see, we had the same idea. :) – dasdom Jul 14 '14 at 14:10
-
Yeah same old questions... – trojanfoe Jul 14 '14 at 14:10
2 Answers
10
Try putting a All Exception Breakpoint by:
1) Opening the left hand side panel (project navigator)
2) Click on the Breakpoints tab in the project navigator (it's the small icon next to the speech bubble)
3) Click the "+" sign on the bottom left of Xcode and choose Add Exception Breakpoint. It should default to All Exception.
4) Run your program again and try to make it crash like you normally do.
Hopefully this will catch it before it crashes. If it did, it'll take you straight to the crashing line in your Xcode coding area.

Zhang
- 11,549
- 7
- 57
- 87
-
1What are your options when it doesn't? I don't call the method length on any object in my file and I'm getting this error. – Jake T. Apr 16 '16 at 16:10
-
If I'm recently getting a `[NSNull length];` exception, it's usually my newest code which caused it. I systematically trace what I tapped on the screen, which screen I'm viewing and which part of the code the program managed to execute up to. I may use a combination of breakpoints and NSLogs to help me. – Zhang Apr 18 '16 at 12:06
0
If you changed anything in your pod files and then you get this error just clean project and rebuild .

LeoNard
- 230
- 1
- 9