2011-04-23 50 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