开发者

Why is this code crashing?

I'm loading an XML file containing about 600 small data sets, which is about 10,000 lines. The data is being used as annotation points on a map. I'm using the TouchXML library to handle the XML. Here is my code:

NSData *XMLData = [NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://skidmoreapps.com/darksky/fetch_info.php"]];
CXMLDocument *doc = [[[CXMLDocument alloc] initWithData:XMLData options:0 error:nil] autorelease];
NSArray *nodes = [doc nodesForXPath:@"//site" error:nil];

for (CXMLElement *node in nodes)
{
    ObservationSite *site = [ObservationSite mapAnnotation];
    [site setCoordinate:CLLocationCoordinate2DMake([[[[node elementsForName:@"lat"] objectAtIndex:0] stringValue] floatValue], [[[[node elementsForName:@"lng"] objectAtIndex:0] stringValue] floatValue])];
    [site setTitle:[[[node elementsForName:@"name"] objectAtIndex:0] stringValue]];
    [site setAddress:[[[node elementsForName:@"address"] objectAtIndex:0] stringValue]];
    [site setUrl:[[[node elementsForName:@"name_l"] objectAtIndex:0] stringValue]];
    [site setAffiliation:[[[node elementsForName:@"affil"] objectAtIndex:0] stringValue]];
    [site setAffiliationUrl:[[[node elementsForName:@"affil_l"] objectAtIndex:0] stringValue]];
    [site setOwner:[[[node elementsForName:@"owner"] objectAtIndex:0] stringValue]];
    [site setFee:[[[node elementsForName:@"fee"] objectAtIndex:0] stringValue]];
    [site setAccess:[[[node elementsForName:@"access"] objectAtIndex:0] stringValue]];
    [site setSky:[[[node elementsForName:@"sky"] objectAtIndex:0] stringValue]];
    [site setWeatherUrl:[[[node elementsForName:@"wx_l"] objectAtIndex:0] stringValue]];
    [site setPads:[[[node elementsForName:@"pads"] objectAtIndex:0] stringValue]];
    [site setParking:[[[node elementsForName:@"parking"] objectAtIndex:0] stringValue]];
    [site setRestrooms:[[[node elementsForName:@"b_rooms"] objectAtIndex:0] stringValue]];
    [site setSleep:[[[node e开发者_开发百科lementsForName:@"sleep"] objectAtIndex:0] stringValue]];
    [site setNotes:[[[node elementsForName:@"notes"] objectAtIndex:0] stringValue]];

    [map addAnnotation:site];
}

After the XML file has downloaded, it crashes with this error:

Why is this code crashing?


From the screenshot I can see that there's a mutateError occuring. This can happen during a fast enumeration if you modify the thing you are enumerating over. Is anything going on that would modify the [self children] collection at the same time as your fast enumeration is running? Are there multiple threads doing things, for example?

If you continue the debugger and allow the exception to be fully thrown, what do you see on the console?

Btw, your .php script appears to be returning a non-valid XML document -- some of the chars are not valid UTF8, as far as my browser is concerned. Maybe not the problem, but worth fixing and ruling out.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜