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!
nil
isn't allowed in containers; if the value could benil
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 GrantimageData == nil
. – trojanfoeNSAssert(imageData != nil, @"Invalid image!");
after the assignment ofimageData
if you think it should never benon-nil
. Then test it thoroughly and you should see if your assertion is correct... – trojanfoe