2011-04-23 57 views
-1

我做了一個矩形按鈕,當用戶點擊它時,他們會去他們的iPod。'NSException'錯誤,按矩形按鈕後崩潰 - 可可觸摸

我在調試時按下按鈕後出現此錯誤。我仔細檢查了iPod代碼,看起來一切正常。

這裏是投擲NSException一個實例後調用調試器中的錯誤:

2011-04-23 18:42:11.580 iApp[1197:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSURL initFileURLWithPath:]: nil string parameter' 
*** Call stack at first throw: 
(
    0 CoreFoundation      0x01369be9 __exceptionPreprocess + 185 
    1 libobjc.A.dylib      0x0115e5c2 objc_exception_throw + 47 
    2 CoreFoundation      0x01322628 +[NSException raise:format:arguments:] + 136 
    3 CoreFoundation      0x0132259a +[NSException raise:format:] + 58 
    4 Foundation       0x00065b12 -[NSURL(NSURL) initFileURLWithPath:] + 90 
    5 iApp        0x000056f3 -[MainViewController setupApplicationAudio] + 148 
    6 iApp        0x00005af0 -[MainViewController viewDidLoad] + 78 
    7 UIKit        0x0037765e -[UIViewController view] + 179 
    8 UIKit        0x00379012 -[UIViewController viewControllerForRotation] + 63 
    9 UIKit        0x00374f76 -[UIViewController _visibleView] + 90 
    10 UIKit        0x0060ea97 -[UIClientRotationContext initWithClient:toOrientation:duration:andWindow:] + 354 
    11 UIKit        0x002f0ba8 -[UIWindow _setRotatableClient:toOrientation:updateStatusBar:duration:force:] + 954 
    12 UIKit        0x00570948 -[UIWindowController transition:fromViewController:toViewController:target:didEndSelector:] + 1053 
    13 UIKit        0x0037b982 -[UIViewController presentModalViewController:withTransition:] + 3151 
    14 iApp       0x00002330 -[MainerViewController goImport:] + 153 
    15 UIKit        0x002c9a6e -[UIApplication sendAction:to:from:forEvent:] + 119 
    16 UIKit        0x003581b5 -[UIControl sendAction:to:forEvent:] + 67 
    17 UIKit        0x0035a647 -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 527 
    18 UIKit        0x003591f4 -[UIControl touchesEnded:withEvent:] + 458 
    19 UIKit        0x002ee0d1 -[UIWindow _sendTouchesForEvent:] + 567 
    20 UIKit        0x002cf37a -[UIApplication sendEvent:] + 447 
    21 UIKit        0x002d4732 _UIApplicationHandleEvent + 7576 
    22 GraphicsServices     0x01b80a36 PurpleEventCallback + 1550 
    23 CoreFoundation      0x0134b064 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52 
    24 CoreFoundation      0x012ab6f7 __CFRunLoopDoSource1 + 215 
    25 CoreFoundation      0x012a8983 __CFRunLoopRun + 979 
    26 CoreFoundation      0x012a8240 CFRunLoopRunSpecific + 208 
    27 CoreFoundation      0x012a8161 CFRunLoopRunInMode + 97 
    28 GraphicsServices     0x01b7f268 GSEventRunModal + 217 
    29 GraphicsServices     0x01b7f32d GSEventRun + 115 
    30 UIKit        0x002d842e UIApplicationMain + 1160 
    31 iApp       0x00001b34 main + 102 
    32 iApp        0x00001ac5 start + 53 
    33 ???         0x00000001 0x0 + 1 
) 
terminate 
+0

可以把你的崩潰容易的代碼? – Jhaliya 2011-04-23 17:59:21

+0

你是什麼意思? – LAA 2011-04-23 18:01:09

+0

在這種情況下,發佈導致錯誤的代碼,以及僅發生異常_without_完整跟蹤可能會更有幫助。錯誤消息說你正在傳遞'nil'參數給' - [NSURL initFileURLWithPath:]';你看過那個嗎? – 2011-04-23 18:05:01

回答

0

如果你看看你的崩潰報告的第一行,它指出要傳遞一個零字符串NSURL的initFileURLWithPath方法:

'NSInvalidArgumentException', reason: '*** -[NSURL initFileURLWithPath:]: nil string parameter' 

從蘋果公司的文件。

傳遞此參數的nil會產生異常。

所以一定要確保發送給initFileURLWithPath方法之前檢查你的NSString,

NSURL* targetFileURL = nil ; 
if(targetFilePath != nil) 
{ 
     targetFileURL = [[NSURL alloc] initFileURLWithPath:targetFilePath]; 
} 
+0

你不想重新聲明'targetFileURL';在第4行放棄'NSURL *'。 – 2011-04-23 18:09:35

+0

謝謝,所有這一切都是我忘了將sound.caf添加到項目中 - 只將它添加到文件夾中。 – LAA 2011-04-23 18:16:16

+0

@Josh Caswell:謝謝,查看我最新的答案。 – Jhaliya 2011-04-23 18:17:30