2

Here's my WebView Code:

[webView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:
[[NSBundle mainBundle] pathForResource:@"index" ofType:@"html"]isDirectory:NO]]];

Here's my Error:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', 
reason: '*** -[NSURL initFileURLWithPath:isDirectory:]: nil string parameter'

Can anyone help? It's saying nil string but the NSURL string is index.html

My only thought is that perhaps the index file isn't stored correctly. It's in the project directory - the same folder as the XCode project file xcodeproj and the info.plist

2
  • there is not space between fileURLWithPath: and isDirectory: Commented Mar 21, 2011 at 16:37
  • that makes no difference. I copy/pasted above code from a tutorial. Commented Mar 21, 2011 at 16:41

2 Answers 2

4

Check that the file is copied to your application bundle. When [[NSBundle mainBundle] pathForResource:ofType:] returns nil very most likely there is no file with this name in the bundle

In Xcode3 right click the "Groups & Files" header in the side bar and select "target membership". Make sure the checkbox in front of index.html is checked.

Sign up to request clarification or add additional context in comments.

1 Comment

It was unchecked. Thanks man. If I have the file in web/index.html how do I do this? It's not accepting pathForResource:@"web/index" ofType:@"html"]
1

URLs have to define how to obtain information, not just what the file is called. This means you have to specify the full URL, like http://www.something.com/index.html or file:///Users/Daniel/Sites/index.html. What you are specifying is a URI not a URL

For the difference between a URL and URI: http://www.damnhandy.com/2007/11/19/uri-vs-url-whats-the-difference/

Apple docs for NSURL: http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSURLRequest_Class/Reference/Reference.html

1 Comment

and fileURLWithPath:isDirectory: creates a URL out of a path.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.