1

I have added some textField and textView on static table view. the code was fine and running on xcode 6.4 / ios 8. * but it is throwing exception which i am not able to track. now i am debugging code on xcode 7.2 (swift2.2)

I tried putting symbolic and and exceptional break point too but no luck :(

following is stack trace of crash, Thanks in advance for your valuable help.

2015-12-14 16:07:07.989 TuteMate[3380:90711] -[NSNull length]: unrecognized selector sent to instance 0x10ccc6af0 

from exceptional breakpoint :

CoreFoundation`-[NSObject(NSObject) doesNotRecognizeSelector:]:
->  0x10504e3c0 <+0>:   pushq  %rbp
    0x10504e3c1 <+1>:   movq   %rsp, %rbp
    0x10504e3c4 <+4>:   pushq  %r15
    0x10504e3c6 <+6>:   pushq  %r14
    0x10504e3c8 <+8>:   pushq  %rbx
    0x10504e3c9 <+9>:   pushq  %rax
    0x10504e3ca <+10>:  movq   %rdx, %r14
    0x10504e3cd <+13>:  movq   %rdi, %rbx
    0x10504e3d0 <+16>:  movq   0x216c79(%rip), %rsi      ; "class"
    0x10504e3d7 <+23>:  callq  *0x229e1b(%rip)           ; (void *)0x000000010730b800: objc_msgSend
    0x10504e3dd <+29>:  movq   %rax, %rdi
    0x10504e3e0 <+32>:  movq   %rbx, %rsi
    0x10504e3e3 <+35>:  movq   %r14, %rdx
    0x10504e3e6 <+38>:  callq  0x10504ed00               ; __CFFullMethodName
    0x10504e3eb <+43>:  movq   %rax, %r14
    0x10504e3ee <+46>:  leaq   0x23fdeb(%rip), %r15      ; @"%@: unrecognized selector sent to instance %p"
    0x10504e3f5 <+53>:  movl   $0x3, %edi
    0x10504e3fa <+58>:  xorl   %eax, %eax
    0x10504e3fc <+60>:  movq   %r15, %rsi
    0x10504e3ff <+63>:  movq   %r14, %rdx
    0x10504e402 <+66>:  movq   %rbx, %rcx
    0x10504e405 <+69>:  callq  0x104fe2560               ; CFLog
    0x10504e40a <+74>:  leaq   0x22b90f(%rip), %rax      ; kCFAllocatorSystemDefault
    0x10504e411 <+81>:  movq   (%rax), %rdi
    0x10504e414 <+84>:  xorl   %esi, %esi
    0x10504e416 <+86>:  xorl   %eax, %eax
    0x10504e418 <+88>:  movq   %r15, %rdx
    0x10504e41b <+91>:  movq   %r14, %rcx
    0x10504e41e <+94>:  movq   %rbx, %r8
    0x10504e421 <+97>:  callq  0x104f35190               ; CFStringCreateWithFormat
    0x10504e426 <+102>: movq   %rax, %rdi
    0x10504e429 <+105>: callq  0x104f33580               ; CFMakeCollectable
    0x10504e42e <+110>: movq   %rax, %rbx
    0x10504e431 <+113>: movq   %rbx, %rdi
    0x10504e434 <+116>: nop    
    0x10504e435 <+117>: nopl   (%rax)
    0x10504e439 <+121>: leaq   0x225300(%rip), %rax      ; __CFOASafe
    0x10504e440 <+128>: cmpb   $0x0, (%rax)
    0x10504e443 <+131>: je     0x10504e459               ; <+153>
    0x10504e445 <+133>: movl   $0x3, %edi
    0x10504e44a <+138>: xorl   %edx, %edx
    0x10504e44c <+140>: xorl   %ecx, %ecx
    0x10504e44e <+142>: xorl   %r8d, %r8d
    0x10504e451 <+145>: movq   %rbx, %rsi
    0x10504e454 <+148>: callq  0x10501b150               ; __CFRecordAllocationEvent
    0x10504e459 <+153>: movq   %rbx, %rdi
    0x10504e45c <+156>: callq  0x1050a3696               ; symbol stub for: _objc_rootAutorelease
    0x10504e461 <+161>: movq   0x218370(%rip), %rdi      ; (void *)0x00000001052690d0: NSException
    0x10504e468 <+168>: leaq   0x234fb1(%rip), %rcx      ; NSInvalidArgumentException
    0x10504e46f <+175>: movq   (%rcx), %rdx
    0x10504e472 <+178>: movq   0x216c4f(%rip), %rsi      ; "exceptionWithName:reason:userInfo:"
    0x10504e479 <+185>: xorl   %r8d, %r8d
    0x10504e47c <+188>: movq   %rax, %rcx
    0x10504e47f <+191>: callq  *0x229d73(%rip)           ; (void *)0x000000010730b800: objc_msgSend
    0x10504e485 <+197>: movq   %rax, %rdi
    0x10504e488 <+200>: callq  0x1050a3738               ; symbol stub for: objc_exception_throw
    0x10504e48d <+205>: nopl   (%rax)

update stack Trace

2015-12-14 16:45:58.932 TuteMate[4000:109943] -[NSNull length]: unrecognized selector sent to instance 0x105b72af0
2015-12-14 16:46:02.651 TuteMate[4000:109943] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSNull length]: unrecognized selector sent to instance 0x105b72af0'
*** First throw call stack:
(
    0   CoreFoundation                      0x000000010594de65 __exceptionPreprocess + 165
    1   libobjc.A.dylib                     0x0000000107bfddeb objc_exception_throw + 48
    2   CoreFoundation                      0x000000010595648d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
    3   CoreFoundation                      0x00000001058a390a ___forwarding___ + 970
    4   CoreFoundation                      0x00000001058a34b8 _CF_forwarding_prep_0 + 120
    5   CoreFoundation                      0x0000000105825dfa CFStringCompareWithOptionsAndLocale + 202
    6   Foundation                          0x0000000106019e37 -[NSString compare:options:range:] + 29
    7   UIKit                               0x00000001069c4e6f -[UIPhysicalKeyboardEvent _matchesKeyCommand:] + 303
    8   UIKit                               0x00000001068e93fd -[UIResponder _keyCommandForEvent:target:] + 364
    9   UIKit                               0x00000001068e95b2 -[UIResponder _keyCommandForEvent:target:] + 801
    10  UIKit                               0x00000001068e95b2 -[UIResponder _keyCommandForEvent:target:] + 801
    11  UIKit                               0x00000001068e95b2 -[UIResponder _keyCommandForEvent:target:] + 801
    12  UIKit                               0x00000001068e95b2 -[UIResponder _keyCommandForEvent:target:] + 801
    13  UIKit                               0x00000001068e95b2 -[UIResponder _keyCommandForEvent:target:] + 801
    14  UIKit                               0x00000001068e95b2 -[UIResponder _keyCommandForEvent:target:] + 801
    15  UIKit                               0x00000001066fb91a -[UIApplication _handleKeyUIEvent:] + 948
    16  UIKit                               0x00000001068e9e53 -[UIResponder _handleKeyUIEvent:] + 79
    17  UIKit                               0x00000001068e9e53 -[UIResponder _handleKeyUIEvent:] + 79
    18  UIKit                               0x00000001068e9e53 -[UIResponder _handleKeyUIEvent:] + 79
    19  UIKit                               0x00000001068e9e53 -[UIResponder _handleKeyUIEvent:] + 79
    20  UIKit                               0x00000001068e9e53 -[UIResponder _handleKeyUIEvent:] + 79
    21  UIKit                               0x00000001068e9e53 -[UIResponder _handleKeyUIEvent:] + 79
    22  UIKit                               0x00000001068e9e53 -[UIResponder _handleKeyUIEvent:] + 79
    23  UIKit                               0x00000001068e9e53 -[UIResponder _handleKeyUIEvent:] + 79
    24  UIKit                               0x00000001068e9e53 -[UIResponder _handleKeyUIEvent:] + 79
    25  UIKit                               0x00000001068e9e53 -[UIResponder _handleKeyUIEvent:] + 79
    26  UIKit                               0x00000001068e9e53 -[UIResponder _handleKeyUIEvent:] + 79
    27  UIKit                               0x00000001068e9e53 -[UIResponder _handleKeyUIEvent:] + 79
    28  UIKit                               0x00000001068e9e53 -[UIResponder _handleKeyUIEvent:] + 79
    29  UIKit                               0x00000001068e9e53 -[UIResponder _handleKeyUIEvent:] + 79
    30  UIKit                               0x00000001068e9e53 -[UIResponder _handleKeyUIEvent:] + 79
    31  UIKit                               0x00000001068e9e53 -[UIResponder _handleKeyUIEvent:] + 79
    32  UIKit                               0x00000001066fb2cd -[UIApplication handleKeyUIEvent:] + 79
    33  UIKit                               0x0000000106991c83 -[UIKeyboardImpl _handleKeyEvent:executionContext:] + 66
    34  UIKit                               0x0000000106b91cde -[UIKeyboardLayoutStar completeRetestForTouchUp:timestamp:interval:executionContext:] + 3356
    35  UIKit                               0x00000001069a0bbd __28-[UIKeyboardLayout touchUp:]_block_invoke + 228
    36  UIKit                               0x00000001070ed724 -[UIKeyboardTaskQueue continueExecutionOnMainThread] + 332
    37  UIKit                               0x00000001069a0ace -[UIKeyboardLayout touchUp:] + 236
    38  UIKit                               0x00000001069a1614 -[UIKeyboardLayout touchesEnded:withEvent:] + 348
    39  UIKit                               0x000000010674b49b -[UIWindow _sendTouchesForEvent:] + 835
    40  UIKit                               0x000000010674c1d0 -[UIWindow sendEvent:] + 865
    41  UIKit                               0x00000001066fab66 -[UIApplication sendEvent:] + 263
    42  UIKit                               0x00000001066d4d97 _UIApplicationHandleEventQueue + 6844
    43  CoreFoundation                      0x0000000105879a31 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
    44  CoreFoundation                      0x000000010586f95c __CFRunLoopDoSources0 + 556
    45  CoreFoundation                      0x000000010586ee13 __CFRunLoopRun + 867
    46  CoreFoundation                      0x000000010586e828 CFRunLoopRunSpecific + 488
    47  GraphicsServices                    0x000000010c9daad2 GSEventRunModal + 161
    48  UIKit                               0x00000001066da610 UIApplicationMain + 171
    49  TuteMate                            0x000000010500128d main + 109
    50  libdyld.dylib                       0x000000010932c92d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException 

UPDATE There are no other viewWillAppeaer, didAppear... methods implemented!

override func viewDidLoad() {
            super.viewDidLoad()
            title = "Profile Edit"
           }

And table viewDelegates are

override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
    // #warning Potentially incomplete method implementation.
    // Return the number of sections.
    return 1
}

override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    // #warning Incomplete method implementation.
    // Return the number of rows in the section.
    return 3
}

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cell = super.tableView(tableView, cellForRowAtIndexPath: indexPath)
    return cell
}
dip
  • 3,548
  • 3
  • 24
  • 36
  • 1
    I suspect you are setting a null value to textField or textView via `.text =` – Akhilrajtr Dec 14 '15 at 10:36
  • 1
    See http://stackoverflow.com/questions/26633242/what-is-causing-nsnull-length-unrecognized-selector-keycommand-error – Clafou Dec 14 '15 at 10:41
  • 1
    post the code where u r setting the value to the textfield – Balaji Kondalrayal Dec 14 '15 at 10:49
  • @Akhilrajtr and Balaji Kondalrayal : Actually it is not caused by textfield.text = null or some thing like that ! it is fine on ios 8 but crashing on ios nine ! BTW i am setting text on viewDidLoad of the controller lets say ***textField.text = "foo" *** and the screen is displaying the text .... but when i tap on that text field and start typing on first hit it crashes and rest of the story is as mentioned ! – dip Dec 14 '15 at 10:59
  • first thing to try is to turn on zombies to make sure it's not sending it to a deallocated NSString object that happened to be located where an NSNull object is now – newacct Dec 15 '15 at 09:11

2 Answers2

5

@dip: From your comments it seems that you need to learn something very important about debugging, and that is: Everything you believe is false. When you say "I don't store null or anything like that", we know that is false. And the second most important rule: Trust the evidence.

The evidence is that a message "length:" which is an NSString method is sent to [NSNull null]. Somewhere you are storing [NSNull null] where you should store a string. Third rule of debugging: You did something wrong. There are no mysterious gremlins trying to upset you, it's your code that's wrong. So find out where you are storing an [NSNull null]. Anything coming from a JSON parser is always a good candidate.

gnasher729
  • 51,477
  • 5
  • 75
  • 98
  • Thanks for your precious post, indeed there is some thing wrong in my code! but i repeat it was working on ios 8 as like charm, but when i install via ad-hoc on ios 9, you cant imagine it was @restarting the device@ and the cause was same this one, to resolve this i upgraded project from swift 1.2 to swift 2.2 (for ios nine) and saw these evidence...and interesting thing is this when apple provide ios upgrade 9.2 i did upgraded which provide a significant event "now only app is crashing not the device".. for your information i am not using any json on this scree.. :( – dip Dec 14 '15 at 12:14
  • 1
    @dip there is no software without a bug, there is no programmer who doesn't make a mistake. finally, there is no enough information in this question, to see, what's going on .... the best how to avoid it is to isolate the trouble. debugging tools are you best friends, not an crash report! i totally agree with gnasher729 "everything you believe is false, trust the evidence!". event hough in your case it may by something wrong behind the scene, you have to show us the evidence, not what you believe ... – user3441734 Dec 14 '15 at 18:59
  • @user3441734 : Humm thanks for positive energy, Actually there is no any code extra code that is effecting that particular class ! see above edit ! – dip Dec 15 '15 at 05:30
-1

Possible Solution:

My issue was caused because I inadvertently clicked on the Key Commands controls in the attribute inspector.

Check out my response here: https://stackoverflow.com/a/36187611/5006807

I hope it helps....

Community
  • 1
  • 1
damote
  • 779
  • 7
  • 4