Question

update: I think the error is coming from a missing key in the data feed and not a key with a null value.

I've been running into a null object by the json interpreter and thought this code would error check and avoid the crash. It's not working though. I need to check to avoid this error message and crash:

imageurl string is <null>
2013-09-09 12:35:26.928 1000 [1539:690b] -[NSNull length]: unrecognized selector sent to instance

if (![imageUrlString isKindOfClass:[NSNull class]])
{

    imageUrlString = [userImageArray objectAtIndex:indexPath.row];


} else {

    cell.thumbnailImageView.image = [UIImage imageNamed:@"rest.png"];

}

fyi - it works if the image string exists and is only crashing when a null object is encountered.

the output from nslog:

when a null obj is encountered: imageurl string is (null)

when it works: imageurl string is http://******.com/uploads/users/35/profile.jpeg

thanks for help

Was it helpful?

Solution

This should do the trick. It don't think that your check for NSNull is not the proper technique to check for a null. Try one of the checks in the first if statement:

/* Either of these checks in the if statement should work */
if ((NSNull *)imageUrlString != [NSNull null] || [@"<null>" isEqualToString:imageUrlString]) {
    imageUrlString = [userImageArray objectAtIndex:indexPath.row];
} else {
    cell.thumbnailImageView.image = [UIImage imageNamed:@"rest.png"];
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top