好的,所以我知道这是一个常见错误,但我在网上找不到任何可以帮助我的东西。
当我输入:
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。
最佳答案
该文件可能在您传递给 -initFileURLWithPath:
的路径中不存在. path
的值是多少?打电话之前?这可能是零,这是我的猜测。
关于ios - 由于未捕获的异常 'NSInvalidArgumentException' 错误而终止应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9960081/