ios - 由于未捕获的异常 '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。

最佳答案

该文件可能在您传递给 -initFileURLWithPath: 的路径中不存在. path 的值是多少?打电话之前?这可能是零,这是我的猜测。

关于ios - 由于未捕获的异常 'NSInvalidArgumentException' 错误而终止应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9960081/

相关文章:

c++ - 使用Visual Studio Express和SDL2在Windows中破坏了SDL_

c++ - 将模板函数传递给另一个模板函数

compiler-errors - 使用ROSE编译器框架的g++编译器错误

android - Debian Sid 上的 Android 内核总是出错

visual-studio-2010 - Visual Studio 2010 C++发行模式问题

ios - ZXing Xcode 4.2 iOS编译错误

android - 在Eclipse上调试Android应用时出错

c++ - 如何在 Windows XP 上正确安装 ffmpeg?

javascript - 编译CoffeeScript

android - 无法在 android opencv 2.3 中导入 ml.h