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];}
私を正しい方向に向けるのを手伝ってください!再度、感謝します!