【问题标题】:Exception could not understand in iphoneiphone中无法理解异常
【发布时间】:2013-12-27 12:36:15
【问题描述】:

嘿,谁能帮我看看这是什么类型的异常,我之前有一个代码和链接是:Application run on simulator but not on device in iphone

这里有谁能知道其中有什么类型的异常吗?有没有内存泄露?

这是下面的日志:

 2013-12-27 17:53:26.814 Skirr[1346:a0b] Application windows are expected to have a root view controller at the end of application launch
2013-12-27 17:53:27.995 Skirr[1346:a0b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSPlaceholderArray initWithObjects:count:]: attempt to insert nil object from objects[0]'
*** First throw call stack:
(
    0   CoreFoundation                      0x032745e4 __exceptionPreprocess + 180
    1   libobjc.A.dylib                     0x021b88b6 objc_exception_throw + 44
    2   CoreFoundation                      0x03228316 -[__NSPlaceholderArray initWithObjects:count:] + 390
    3   CoreFoundation                      0x0324bce9 +[NSArray arrayWithObject:] + 73
    4   Skirr                               0x000093bd -[SlideViewController viewDidLoad] + 1597
    5   UIKit                               0x00e2d318 -[UIViewController loadViewIfRequired] + 696
    6   UIKit                               0x00e2d5b4 -[UIViewController view] + 35
    7   UIKit                               0x00e473e2 -[UINavigationController _startCustomTransition:] + 778
    8   UIKit                               0x00e540c7 -[UINavigationController _startDeferredTransitionIfNeeded:] + 688
    9   UIKit                               0x00e54cb9 -[UINavigationController __viewWillLayoutSubviews] + 57
    10  UIKit                               0x00f8e181 -[UILayoutContainerView layoutSubviews] + 213
    11  UIKit                               0x00d84267 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 355
    12  libobjc.A.dylib                     0x021ca81f -[NSObject performSelector:withObject:] + 70
    13  QuartzCore                          0x005622ea -[CALayer layoutSublayers] + 148
    14  QuartzCore                          0x005560d4 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 380
    15  QuartzCore                          0x00555f40 _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 26
    16  QuartzCore                          0x004bdae6 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 294
    17  QuartzCore                          0x004bee71 _ZN2CA11Transaction6commitEv + 393
    18  QuartzCore                          0x004bf544 _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 92
    19  CoreFoundation                      0x0323c4ce __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 30
    20  CoreFoundation                      0x0323c41f __CFRunLoopDoObservers + 399
    21  CoreFoundation                      0x0321a344 __CFRunLoopRun + 1076
    22  CoreFoundation                      0x03219ac3 CFRunLoopRunSpecific + 467
    23  CoreFoundation                      0x032198db CFRunLoopRunInMode + 123
    24  GraphicsServices                    0x034ce9e2 GSEventRunModal + 192
    25  GraphicsServices                    0x034ce809 GSEventRun + 104
    26  UIKit                               0x00d19d3b UIApplicationMain + 1225
    27  Skirr                               0x000055a2 main + 130
    28  libdyld.dylib                       0x06896725 start + 0
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb) 

【问题讨论】:

  • 请也分享功能-[SlideViewController viewDidLoad]。
  • 实际的崩溃是当您尝试将nil 放入一个调用initWithObjects:count: 的数组中时。 (根据消息,您在设置初始视图控制器时也有问题。)
  • 注意,这是this question 的错误消息,OP 在新问题中发布了错误消息,而不是将其添加到原始问题中。
  • @PhillipMills,对,但在模拟器数组中找不到 nil 它只在设备中,这是您会得到实际问题的链接:stackoverflow.com/questions/20800108/…
  • 由于该错误与您已经提出的问题有关,因此您不应该重新提出问题

标签: ios iphone objective-c exception


【解决方案1】:

看看这个来自

link

尝试从 objects[0] 中插入 nil 对象

您正在插入或处理 nil 对象,您可以参考上面链接中给出的那一行

【讨论】:

    【解决方案2】:

    错误

    * 由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“* -[__NSPlaceholderArray initWithObjects:count:]: 尝试从 objects[0] 插入 nil 对象”

    发生是因为您试图将nil 值添加到NSArray。在查看另一个问题的代码后,它崩溃的特定代码行是

    [_slideNavigationController setViewControllers:[NSArray arrayWithObject:initalViewController] animated:NO];
    

    这里崩溃是因为两件事之一

    1) initalViewControllernil 所以当你使用 arrayWithObject 添加它时它会崩溃。

    2) setViewControllers:[NSArray arrayWithObject:initalViewController] 导致错误,因为[NSArray arrayWithObject:initalViewController]nil 设置为采用NSArray 的方法setViewControllers:

    我会说是选项 (1) 导致了您的问题,尽管当调用 arrayWithObject 时发生崩溃。

    【讨论】:

    • 但在模拟器中运行完美。但在设备中却不是为什么?
    • 如果没有更多信息,真的很难说,但是 `UIViewController *initalViewController = [self.delegate initialViewController];` 绝对是 nil。
    • 是的,在设备中它为零,但在模拟器中,我怎样才能让你找到我的解决方案,请吃一些菠菜并帮助我
    • 我无法从您的代码中得知更多信息。您将不得不添加一些断点并循环通过将代码放入方法中,直到找到它的确切位置。我在回答中所包含的内容都是基于您提供的错误和代码。
    【解决方案3】:

    检查您的 main.m。最后一个参数应设置为实现 UIApplicationDelegate 协议的类的名称,或者您可以尝试使用最后一个参数,如 NSStringFromClass([AppDelegate class])

    请查看此链接,它可能对您有所帮助。 click here

    【讨论】:

    • 这与问题中的异常有何联系?
    • Yurish,请查看崩溃日志的第一行。
    • 这与崩溃无关。第一行更像是一个警告,它不会使应用程序崩溃,至少它只会提供一个空白屏幕,但它仍然会运行。崩溃日志中的第二行是导致崩溃的错误。这与 main.m -1 中的 AppDelegate 不正确无关。
    • 很明显*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSPlaceholderArray initWithObjects:count:]: attempt to insert nil object from objects[0]' 是导致应用程序崩溃的问题。请注意由于未捕获的异常而终止应用程序...
    • @prashant 那么这与 main.m 有什么关系呢?错误发生在 -[SlideViewController viewDidLoad] viewDidLoad 是被调用的方法中。在该方法中,这个+[NSArray arrayWithObject:] 被称为arrayWithObjects。所以当它被调用时,他们试图向被接受的数组添加一个nil 值。这就是attempt to insert nil object 的原因所以这与你在main.m 中的回答无关。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-23
    • 2011-06-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多