2012-03-31 93 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); 

看文件名是一样的。

相关问题