我遇到了这个问题,我的 iPhone 上出现了这个错误:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSConcreteData initWithContentsOfURL:options:error:]: nil URL argument'
我正在尝试解析一些 XML 数据,当我在模拟器上尝试时,我没有收到任何错误,但是每当我在 iOS 设备上尝试时,我的控制台中都会出现错误!
这是我解析 XML 的代码:
- (ICB_WeatherConditions *)initWithQuery:(NSString *)query {
if (self = [super init])
{
CXMLDocument *parser = [[[CXMLDocument alloc] initWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://www.google.com/ig/api?weather=%@", query]] options:0 error:nil] autorelease];
condition = [[[[[parser nodesForXPath:@"/xml_api_reply/weather/current_conditions/condition" error:nil] objectAtIndex:0] attributeForName:@"data"] stringValue] retain];
location = [[[[[parser nodesForXPath:@"/xml_api_reply/weather/forecast_information/city" error:nil] objectAtIndex:0] attributeForName:@"data"] stringValue] retain];
day2c = [[[[[parser nodesForXPath:@"/xml_api_reply/weather/forecast_conditions/condition" error:nil] objectAtIndex:0] attributeForName:@"data"] stringValue] retain];
day3c = [[[[[parser nodesForXPath:@"/xml_api_reply/weather/forecast_conditions/condition" error:nil] objectAtIndex:1] attributeForName:@"data"] stringValue] retain];
currentTemp = [[[[[parser nodesForXPath:@"/xml_api_reply/weather/current_conditions/temp_f" error:nil] objectAtIndex:0] attributeForName:@"data"] stringValue] integerValue];
lowTemp = [[[[[parser nodesForXPath:@"/xml_api_reply/weather/forecast_conditions[2]/low" error:nil] objectAtIndex:0] attributeForName:@"data"] stringValue] integerValue];
highTemp = [[[[[parser nodesForXPath:@"/xml_api_reply/weather/forecast_conditions/high" error:nil] objectAtIndex:0] attributeForName:@"data"] stringValue] integerValue];
conditionImageURL = [[NSURL URLWithString:[NSString stringWithFormat:@"http://www.google.com%@", [[[[parser nodesForXPath:@"/xml_api_reply/weather/current_conditions/icon" error:nil] objectAtIndex:0] attributeForName:@"data"] stringValue]]] retain];
}
return self;}
这是我发送查询的代码:
- (void)showWeatherFor:(NSString *)query {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
ICB_WeatherConditions *weather = [[ICB_WeatherConditions alloc] initWithQuery:query];
self.conditionsImage = [[UIImage imageWithData:[NSData dataWithContentsOfURL:weather.conditionImageURL]] retain];
[self performSelectorOnMainThread:@selector(updateUI:) withObject:weather waitUntilDone:NO];
[pool release];}
请帮我指出正确的方向!再次感谢!