路径不起作用

时间:2010-08-09 00:29:16

标签: iphone

NSBundle *thisBundleb = [NSBundle mainBundle];

pathb = [thisBundleb pathForResource:[a3 objectAtIndex:0] ofType:@"html"];

NSURL   *instructionsURLb = [[NSURL alloc] initFileURLWithPath:pathb];
[webView loadRequest:[NSURLRequest requestWithURL:instructionsURLb]];       
*由于未捕获的异常'NSInvalidArgumentException'而终止应用程序,原因:'* - [NSURL initFileURLWithPath:]:nil字符串参数'**

我做错了什么?

2 个答案:

答案 0 :(得分:1)

您的index.html实际上是Index.html吗?我相信pathForResource:ofType区分大小写。

答案 1 :(得分:1)

pathForResource:ofType:返回nil,而initFileURLWithPath:正在抱怨它。陷阱那样的错误:

if(nil == pathb) {
    NSLog("Couldn't find object named %@", [a3 objectAtIndex:0]);
} else {
    NSURL   *instructionsURLb = [[NSURL alloc] initFileURLWithPath:pathb];
    [webView loadRequest:[NSURLRequest requestWithURL:instructionsURLb]];          
}

并仔细检查您是否正在搜索捆绑包中实际存在的对象。