ios - 由于未捕获的异常 'NSInvalidArgumentException' 错误而终止应用程序

标签 ios compiler-errors avfoundation avaudioplayer nsurl

好的,所以我知道这是一个常见错误,但我在网上找不到任何可以帮助我的东西。
当我输入:

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/

相关文章:

c++ - 使用Codelite IDE输入2D阵列时出现问题

ios6 - 使用 AVFoundation iOS 6 切换相机

iphone - AVFoundation - 重新定时 CMSampleBufferRef 视频输出

ios - 如何确定正在使用哪个Appstore用户?

ios - 表格单元格中的 MPMoviePlayer 崩溃

c - C编程报错后报错信息中的 "label"是什么?

ios - Swift 错误消息中的 '(String)' 和 'String' 有什么区别

ios - 使用 xcode AVFoundation 扫描 EAN13 条码时发生奇怪

ios - UIImageView 不响应居中

ios - 如何知道应用程序运行时iPhone的时钟是否改变?