Reputation: 330
I have 10 html which are stored in an array...I want to display each html by means of button click...But my app got crashed.. Here is the code..
int xpos=10,ypos=10;
for (int i=0; i<[array count]; i++) {
UIButton *but=[UIButton buttonWithType:UIButtonTypeRoundedRect];
[but setTag:i];
but.backgroundColor=[UIColor redColor];
but.frame=CGRectMake(xpos, ypos, 50, 50);
xpos+=90;
[self.view addSubview:but];
[but addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchDown];
}
- (void)buttonClicked:(UIButton *)sender {
NSString *str=[array objectAtIndex:sender.tag];
[webview loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:str ofType:@"html"]isDirectory:NO]]];
[webview release];
}
How to overcome this problem? here is the crash report
24/10/11 4:56:08 PM Loading HTML[4655] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '* -[NSURL initFileURLWithPath:isDirectory:]: nil string parameter'
Upvotes: 1
Views: 749
Reputation: 106
Looks like [[NSBundle mainBundle] pathForResource:str ofType:@"html"]
results in nil - which means that the file could now be found in your main bundle. Make sure that file with that name and extension exists. Remember that file names are case sensitive.
Upvotes: 0
Reputation: 6268
24/10/11 4:56:08 PM Loading HTML[4655] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '* -[NSURL initFileURLWithPath:isDirectory:]: nil string parameter'
Your error log states that you are sending nil for the value str.
Please check the value of str. That should fix the problem. May be you have misspelled the name of the file.
Update for comment
Try replacing your file name there instead of getting it at run time.
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"yourHtmlFileNameGoesHere" ofType:@"html"]isDirectory:NO]]];
If the above works then you should be checking the array.
Upvotes: 0
Reputation: 17478
Where you are initializing the webview?
Please remove the [webview release];
and try now.
Upvotes: 1