我收到以下错误,请帮我解决一下。我的xcode因以下错误而中止
Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[NSMutableArray objectAtIndex:]: index 0 beyond bounds for empty array'
*** Call stack at first throw:
(
0 CoreFoundation 0x0140a5a9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x0155e313 objc_exception_throw + 44
2 CoreFoundation 0x014000a5 -[__NSArrayM objectAtIndex:] + 261
3 UMMCelebrity 0x00043903 -[UMMFlickrView photoGallery:urlForPhotoSize:atIndex:] + 115
4 UMMCelebrity 0x0004a9d6 -[FGalleryViewController createGalleryPhotoForIndex:] + 422
5 UMMCelebrity 0x0004a5ac -[FGalleryViewController loadThumbnailImageWithIndex:] + 172
6 UMMCelebrity 0x0004a189 -[FGalleryViewController preloadThumbnailImages] + 281
7 UMMCelebrity 0x00046f84 -[FGalleryViewController loadView] + 2132
8 UIKit 0x0029d00e -[UIViewController view] + 56
9 UMMCelebrity 0x00043050 -[UMMFlickrView pushphotoview] + 192
10 UMMCelebrity 0x000446c6 -[UMMFlickrView connection:didReceiveData:] + 2230
11 Foundation 0x00996835 _NSURLConnectionDidReceiveData + 159
12 CFNetwork 0x033bde72 _ZN19URLConnectionClient21_clientDidReceiveDataEPK8__CFDataPNS_26ClientConnectionEventQueueE + 262
13 CFNetwork 0x0348a6b3 _ZN19URLConnectionClient26ClientConnectionEventQueue33processAllEventsAndConsumePayloadEP20XConnectionEventInfoI12XClientEvent18XClientEventParamsEl + 247
14 CFNetwork 0x0348a9cf _ZN19URLConnectionClient26ClientConnectionEventQueue33processAllEventsAndConsumePayloadEP20XConnectionEventInfoI12XClientEvent18XClientEventParamsEl + 1043
15 CFNetwork 0x033b5c80 _ZN19URLConnectionClient13processEventsEv + 100
16 CFNetwork 0x033b5acf _ZN17MultiplexerSource7performEv + 251
17 CoreFoundation 0x013eb8ff __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
18 CoreFoundation 0x0134988b __CFRunLoopDoSources0 + 571
19 CoreFoundation 0x01348d86 __CFRunLoopRun + 470
20 CoreFoundation 0x01348840 CFRunLoopRunSpecific + 208
21 CoreFoundation 0x01348761 CFRunLoopRunInMode + 97
22 GraphicsServices 0x018e21c4 GSEventRunModal + 217
23 GraphicsServices 0x018e2289 GSEventRun + 115
24 UIKit 0x001fbc93 UIApplicationMain + 1160
25 UMMCelebrity 0x00001d29 main + 121
26 UMMCelebrity 0x00001ca5 start + 53
)
terminate called after throwing an instance of 'NSException'
答案 0 :(得分:0)
您在空objectAtIndex:
上使用参数0
呼叫NSMutableArray
。
[NSMutableArray objectAtIndex:]: index 0 beyond bounds for empty array
如果您知道NSMutableArray
可以为空,则在尝试访问元素之前,应考虑在其上调用count
以查看它是否确实包含任何元素。
答案 1 :(得分:0)
显然,NSMutableArray
中有一个空的-[UMMFlickrView photoGallery:urlForPhotoSize:atIndex:]
,并且您使用参数0发送了objectAtIndex:
。
答案 2 :(得分:0)
这意味着你的NSMutableArray是空的。我认为你没有为NSMutableArray分配内存。阅读此链接,它可能对您有所帮助。 http://www.roseindia.net/answers/viewqa/Mobile-Applications/14614-NSMutableArray-Example-Code.html
答案 3 :(得分:0)
可能是第4次点击没有任何内容被推入数组,我不确定,因为我不知道你要做什么。如果你可以添加将对象添加到你的数组中的代码行,我们可以帮助你。
发生此错误是因为数组肯定是空的。