我有這個問題,我不斷收到這個錯誤在我的控制檯:除了有一個數組之外的空數組的NSRangeException?
* Terminating app due to uncaught exception 'NSRangeException', reason: '* -[__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",query]] options:0 error:nil];
weathercondition = [[[worldweather nodesForXPath:@"/data/current_condition/weatherIconUrl" error:nil] objectAtIndex:0] stringValue];
位置是Xcode是使用是威廉姆斯,CA和發送的查詢
Williams+CA
當我插入到這一點我的網址,它的工作原理,我得到我的XML文件,但爲什麼我得到這個MES鼠標在我的控制檯?
這讓我瘋狂。所有的幫助將非常感謝!提前致謝!
讓我知道如果你NSLog(@「class:%@」,[[worldweather nodesForXPath:@「/ data/current_condition/weatherIconUrl」error:nil] class]); – Ladislav
這是我現在的控制檯:2012-06-19 20:17:38.441預測器[10795:c07] Williams + CA 2012-06-19 20:17:38.799預測器[10795:630b]( ) 2012- 06-19 20:17:38.799陣列中的預測器[10795:630b]元素:0 2012-06-19 20:17:38.800預測器[10795:630b] ***由於未捕獲的異常'NSRangeException' :'*** - [__ NSArrayI objectAtIndex:]:索引0超出空數組邊界' – sridvijay
我知道,但添加之前,你有天氣條件= ...只需添加我的行NSLog(@「class:%@」,[ [worldweather nodesForXPath:@「/ data/current_condition/weatherIconUrl」error:nil] class]);並讓我知道現在控制檯輸出什麼 – Ladislav