Search code examples
iosobjective-cpluginsios7nsurl

'NSInvalidArgumentException', reason: '*** -[NSURL initFileURLWithPath:]: nil string parameter'


I am scratching my head as to what is happening here.....The print plugin is not working... I am trying to add a printer plugin to an application..after mapping up my xml and loading html file, I do not see an error in Xcode. However, as I run the application it crashes and the log states :

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

I am worried as I am unable to overcome it since the last 24 hours...Any help will be great..or if someone can let me know of how to exactly get a printer plugin working in my app will be good....The code I am using is

// Set the base URL to be the www directory.
NSString* wwwFilePath = [[NSBundle mainBundle] pathForResource:@"www" ofType:nil];
NSURL*    baseURL     = [NSURL fileURLWithPath:wwwFilePath];

Solution

  • There is no need to post so much code. Just post relevant code which are the following two lines:

    NSString* wwwFilePath = [[NSBundle mainBundle] pathForResource:@"www" ofType:nil];
    NSURL*    baseURL     = [NSURL fileURLWithPath:wwwFilePath];
    

    The problems is that wwwFilePath is nil which means that you do not have a file named www in your app bundle.

    Either add the missing file or update the name of the file in the call to pathForResource:ofType: with the proper filename.

    BTW - the two lines can simply be:

    NSURL *basEURL = [[NSBundle mainBundle] URLForResource:@"www" withExtension:nil];
    

    but again you still need to pass in a valid filename/extension.