【问题标题】:Path is not working路径不工作
【发布时间】:2010-08-09 00:29:16
【问题描述】:
NSBundle *thisBundleb = [NSBundle mainBundle];

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

NSURL   *instructionsURLb = [[NSURL alloc] initFileURLWithPath:pathb];
[webView loadRequest:[NSURLRequest requestWithURL:instructionsURLb]];       

[a3 objectAtIndex:0]=index 的值,但是当我像这样通过时,我得到了 * 由于未捕获的异常 'NSInvalidArgumentException' 导致应用程序终止,原因:'* -[NSURL initFileURLWithPath:]: nil string parameter'**

我做错了什么?

【问题讨论】:

    标签: iphone


    【解决方案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]];          
    }
    

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

    【讨论】:

    • 如果我输入 @"index" 那么它就存在,那么它工作正常。否则不是:(我试过你的代码,我得到了这个 -[UIRoundedRectButton length]: unrecognized selector sent to instance 0x3b14ab0 2010-08-09 08:40:37.924 ramdev[1641:207] *** 由于未捕获的异常而终止应用程序' NSInvalidArgumentException',原因:'*** -[UIRoundedRectButton 长度]:无法识别的选择器发送到实例 0x3b14ab0'
    • 那么[a3 objectAtIndex:0] 返回的不是你所期望的。验证 a3 数组是否有效,并且它实际上在索引 0 处包含字符串 @"index"
    • 听起来不像 [a3 objectAtIndex:0] == @"index",那么。
    • 嘿 [a3 objectAtIndex:0] == index not @"index" 我应该让它像@"index"吗?哦,上帝让我试试
    • 我认为 rsource 的路径查找此路径 file://localhost/Users/applefan/Library/Application%20Support/iPhone%20Simulator/3.1.3/Applications/A582538C-75CF-48BB-B864 -74CCA1BA6900/ramdev.app/ 所以我认为我必须将它与索引一起附加,然后它才会变得完整???
    【解决方案2】:

    你的index.html 真的叫Index.html 吗?我相信pathForResource:ofType 区分大小写。

    【讨论】:

    • 似乎只在设备(ipad)上区分大小写,在模拟器中不区分大小写。
    猜你喜欢
    • 2014-12-27
    • 2018-06-04
    • 1970-01-01
    • 1970-01-01
    • 2022-11-02
    • 1970-01-01
    • 2022-11-18
    • 1970-01-01
    • 2019-01-19
    相关资源
    最近更新 更多