Objective c 从5到6个IOS生成时出错
我有适用于IOS 5.1的IPad应用程序,现在我正在尝试为6.0构建它,但出现了一个错误: *由于未捕获异常“NSInvalidArgumentException”而终止应用程序,Objective c 从5到6个IOS生成时出错,objective-c,ios6,Objective C,Ios6,我有适用于IOS 5.1的IPad应用程序,现在我正在尝试为6.0构建它,但出现了一个错误: *由于未捕获异常“NSInvalidArgumentException”而终止应用程序,原因: -[NSFileManager copyItemAtPath:toPath:错误:]:源路径为零' “ 我发现这个问题在哪里,但我不知道如何纠正它 在myAppDelegate中 -(void)copyFileWithName:(NSString*)name Extension:(NSString*)exte
原因: -[NSFileManager copyItemAtPath:toPath:错误:]:源路径为零' “ 我发现这个问题在哪里,但我不知道如何纠正它 在myAppDelegate中
-(void)copyFileWithName:(NSString*)name Extension:(NSString*)extension ToDir:(NSString*)dirName withName:(NSString*)newName
{
NSString *folderPath = dirName;
NSString *filePathDocTxt = [folderPath stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.%@", newName, extension]];
NSString *filePathBundleTxt = [[NSBundle mainBundle] pathForResource:name ofType:extension];
//when i comment these two lines, my code compiles success, but i need these code
if(![[NSFileManager defaultManager] fileExistsAtPath:filePathDocTxt])
[[NSFileManager defaultManager] copyItemAtPath:filePathBundleTxt toPath:filePathDocTxt error:nil];
}
错误是copyItemAtPath方法的源路径为零。 因为您从捆绑包(应用程序)复制到另一个文件夹,这意味着文件不在目标文件夹中 确保您尝试复制的文件存在并正确添加到目标(在Xcode中) 若要解决崩溃问题,请添加一个if,以在项目不存在时排除复制/断言它
NSString *filePathBundleTxt = [[NSBundle mainBundle] pathForResource:name ofType:extension];
assert(filePathBundleTxT);
对不起,我是IOS开发新手,我该怎么办?这些捆绑包在哪里?你是说文件不在我的项目路径中,我想如果它是真的,我无法在5.1中编译它,但我会看看,谢谢。错误是源路径为nil==在应用程序中找不到文件在这种情况下,这不能解释问题或提供解决方案。它为了有用,需要扩展;因为它是对原始问题的评论。