我遇到了这个问题,我在控制台中不断收到此错误:
* 由于未捕获的异常“NSRangeException”而终止应用程序,原因:“* -[__NSArrayI objectAtIndex:]: index 0 beyond bounds for empty array”
这是我从 XML 文档中检索数据的代码:
CXMLDocument *worldweather = [[CXMLDocument alloc]initWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://free.worldweatheronline.com/feed/weather.ashx?q=%@&format=xml&num_of_days=4&key=0ded69e02b171832121504",查询]]选项:0错误:无];
weathercondition = [[[worldweather nodesForXPath:@"/data/current_condition/weatherIconUrl" error:nil] objectAtIndex:0] stringValue];
Xcode 使用的位置是 Williams, CA,发送的查询是
威廉姆斯+CA
当我将它插入我的 URL 时,它可以工作并且我得到了我的 XML 文件,但是为什么我在我的控制台中收到这条消息???
这真让我抓狂。非常感谢所有帮助!提前致谢!