1
votes

I'm looking at the crash log for a device that's testing an app and I see the following lines...

objc_exception_throw + 33

[__NSArrayM insertObject:atIndex:] +187

The code where this happens is below. appData is an NSDictionary, and I'm expecting imageUrl to be a URL to a png file on the internet.

for (int i = 1; i <= [self getNumberOfScreenshots]; i++) {
    pathToUrl = @"screenshot_";
    pathToUrl = [pathToUrl stringByAppendingString:[[NSNumber numberWithInt:i] stringValue]];
    imageUrl = [self.appData valueForKey:pathToUrl];
    imageData = [[NSData alloc]initWithContentsOfURL:[NSURL URLWithString:imageUrl]];
    [NSMutableArrayObj addObject:imageData];
}

What would cause this type of error? The error happens very rarely..could it be that imageData is sometimes nil because it fails to download the png image off the url, so that throws that exception when I try to add it to the NSMutableArrayObj?

Thanks!

1
Yes, nil isn't allowed in containers; if the value could be nil that would be a problem. You don't say which exception was raised though; the trace implies that an exception was thrown. It probably describes the error more precisely.Kevin Grant
Yeah add more error checking and reject images where imageData == nil.trojanfoe
Thanks for the help! I'll add the error checking, I'm guessing it's the nil issue. i can't see exactly what exception is being thrown from the rest of the trace... the topmost line is __exceptionPreprocess + 163user1467188
Add NSAssert(imageData != nil, @"Invalid image!"); after the assignment of imageData if you think it should never be non-nil. Then test it thoroughly and you should see if your assertion is correct...trojanfoe

1 Answers

0
votes

there may two reasons as you have not described error more specically

1) Actually your not allocating the memory to array

2) inserting nil value to array. To stop inserting nil do this:

 if(imageData)
 {
   [NSMutableArrayObj addObject:imageData];
 }