3
votes

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];
3

3 Answers

11
votes

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.

0
votes

Reason is in your error log reason: '* -[NSURL initFileURLWithPath:]: nil, You cann't pass nil parameter to initFileURLWithPath:. Just check and call this method as below.

NSString* wwwFilePath = [[NSBundle mainBundle] pathForResource:@"www" ofType:nil];
if( wwwFilePath)
   NSURL*    baseURL     = [NSURL fileURLWithPath:wwwFilePath];
0
votes

By the commend in your source code, you're stating that www is a directory.

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

I don't think pathForResource will consider a directory a valid resource. Remember that a resource is a file, and this method will try to search in the given bundle for a resource with that name.