gpt4 book ai didi

nsurl - 从 mainBundle pathForResource 创建 URL 找不到文件

转载 作者:行者123 更新时间:2023-12-02 05:40:03 27 4
gpt4 key购买 nike

我正在尝试创建一个 NSURL,其中包含指向我项目中音频文件的链接。我已经复制了音频文件(.m4a 文件),我正在使用这一行用其中之一填充 NSURL:

NSURL *fileToBePlayed = [[NSURL alloc] initWithString:[NSString stringWithString:[[NSBundle mainBundle] pathForResource:@"A3" ofType:@"m4a" inDirectory:@"Sounds"]]];

我在这条线上遇到了以下崩溃:

2012-06-20 12:32:05.307 TestPlayer[29184:10703] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSPlaceholderString initWithString:]: nil argument'

我不确定nil 参数 到底是什么意思。该文件肯定在那里,在正确的位置,已被复制到项目中,等等。我看不出它找不到该文件的任何原因。如果我将文件名更改为某个不存在的虚构文件,我会遇到同样的崩溃,所以大概是出于某种原因它看不到该文件。有什么想法吗?

如果我把它分成不同的行,这里的前两行没问题,是第三行崩溃了,NSURL 行:

NSString *testString = [[NSString alloc] init];
testString = [[NSBundle mainBundle] pathForResource:@"A3" ofType:@"m4a"];
NSURL *fileToBePlayed = [[NSURL alloc] initWithString:testString];

最佳答案

由于某种原因,文件没有被添加到目标中。谢谢你,Xcode。

关于nsurl - 从 mainBundle pathForResource 创建 URL 找不到文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11118637/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com