簡體   English   中英

應用程序因錯誤而崩潰:-[NSNull 長度]:無法識別的選擇器發送到實例

[英]App crashing with error: -[NSNull length]: unrecognized selector sent to instance

這一行[self.label setFont:[MyUtilityClass fontWithSize:13.0f]]; 代碼給了我 -[NSNull length]: 崩潰。 很多人都能猜到的label是 UILabel。 我能想到的唯一合乎邏輯的解釋是 UILabel 文本為空。 我將在下面發布我的實用程序類,以防萬一。

我的實用程序類

 + (UIFont *) fontWithSize : (CGFloat) size
   {
UIFont *font = [UIFont fontWithName:@"Roboto-Regular" size:size];

return font;
    }

編輯:這是我收到的錯誤消息。 如果您需要,我可以復制和粘貼原始數據。 這是用戶根據 crashlytics 收到的崩潰。

致命異常:NSInvalidArgumentException

  -[NSNull length]: unrecognized selector sent to instance 0x378e23f0

這是崩潰的原始數據。

Thread : Fatal Exception: NSInvalidArgumentException
0  CoreFoundation                 0x297c3c1f __exceptionPreprocess + 126
1  libobjc.A.dylib                0x36f97c8b objc_exception_throw + 38
2  CoreFoundation                 0x297c9039 __methodDescriptionForSelector
3  CoreFoundation                 0x297c6f57 ___forwarding___ + 714
4  CoreFoundation                 0x296f8df8 _CF_forwarding_prep_0 + 24
5  UIKit                          0x2cc8b1b5 -[UILabel _setFont:] + 100
6  MyApp                        0x00137c29 -[MyViewController initUI] (MyViewController.m:90)
7  MyApp                       0x0013765b -[MyViewController viewDidLoad] (MyViewController.m:51)
8  UIKit                          0x2cc82f8f -[UIViewController loadViewIfRequired] + 602
9  UIKit                          0x2cd2cd95 -[UINavigationController _layoutViewController:] + 32
10 UIKit                          0x2cd2ccbd -[UINavigationController _updateScrollViewFromViewController:toViewController:] + 228
11 UIKit                          0x2cd2c253 -[UINavigationController _startTransition:fromViewController:toViewController:] + 74
12 UIKit                          0x2cd2bf83 -[UINavigationController _startDeferredTransitionIfNeeded:] + 578
13 UIKit                          0x2cd2bced -[UINavigationController __viewWillLayoutSubviews] + 44
14 UIKit                          0x2cd2bc81 -[UILayoutContainerView layoutSubviews] + 184
15 UIKit                          0x2cc804d7 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 514
16 QuartzCore                     0x2c6a8a0d -[CALayer layoutSublayers] + 136
17 QuartzCore                     0x2c6a43e5 CA::Layer::layout_if_needed(CA::Transaction*) + 360
18 QuartzCore                     0x2c6a426d CA::Layer::layout_and_display_if_needed(CA::Transaction*) + 16
19 QuartzCore                     0x2c6a3c51 CA::Context::commit_transaction(CA::Transaction*) + 224
20 QuartzCore                     0x2c6a3a55 CA::Transaction::commit() + 324
21 UIKit                          0x2cc78965 _afterCACommitHandler + 132
22 CoreFoundation                 0x2978a3b5 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 20
23 CoreFoundation                 0x29787a73 __CFRunLoopDoObservers + 278
24 CoreFoundation                 0x29787e7b __CFRunLoopRun + 914
25 CoreFoundation                 0x296d6211 CFRunLoopRunSpecific + 476
26 CoreFoundation                 0x296d6023 CFRunLoopRunInMode + 106
27 GraphicsServices               0x30a8f0a9 GSEventRunModal + 136
28 UIKit                          0x2cce21d1 UIApplicationMain + 1440
29 MyApp                        0x000a07e7 main (main.m:16)
30 libdyld.dylib                  0x37517aaf start + 2

您很可能試圖獲得您認為是NSString但實際上是NSNull

我的代碼遇到了這個問題並通過使用系統字體解決了它。 情況是它無法加載我在代碼中指定的字體。 嘗試並讓我知道它是否有幫助。

快樂編碼,干杯,Ratneshwar

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM