2012-03-31 94 views
0

好吧,所以我知道這是一個常見的錯誤,但我找不到任何東西可以幫助我在線。終止應用程序由於未捕獲的異常'NSInvalidArgumentException'錯誤

當我輸入:

NSString *path = [[NSBundle mainBundle] pathForResource:@"backgroundLoop" ofType:@"m4a"]; 
AVAudioPlayer* theAudio = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL]; 
[theAudio play]; 

到我的應用程序(在-viewDidLoad方法),我得到這個錯誤:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSURL initFileURLWithPath:]: nil string parameter'

First throw call stack: (0x1a31022 0x1ed9cd6 0x19d9a48 0x19d99b9 0xcad53b 0xcad4c5 0x2f85 0x10cba1e 0x102a401 0x102a670 0x102a836 0x103172a 0x2d8d 0x1002386 0x1003274 0x1012183 0x1012c38 0x1006634 0x317fef5 0x1a05195 0x1969ff2 0x19688da 0x1967d84 0x1967c9b 0x1002c65 0x1004626 0x2bbc 0x2b55) terminate called throwing an exception(lldb)

請注意:我使用ARC。

回答

0

該文件可能不存在於傳遞給-initFileURLWithPath:的路徑中。撥打電話前,path的價值是多少?這可能是零,這是我的猜測。

+0

路徑的值在調用之前不會直接顯示。我應該把它放進去嗎?如果是這樣,怎麼樣? – 2012-04-02 19:48:11

+0

您可以在調試控制檯提示符處輸入'po path'來打印它。 – user1118321 2012-04-02 21:04:06

0

只需使用的NSLog:

NSLog(@"%@", path); 

看文件名是一樣的。

相關問題