I have listing of videos in UITableView which uses custom class. This is tabbar application. When I scroll down to 8th video, and go to next screen and when I come back to video listing screen, the app crashes. I tried to debug but cannot figure out the issue. This is what I get from debugger.
2016-06-08 12:47:46.919 Votocast[2283:453809] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 8 beyond bounds for empty array'
*** First throw call stack:
(
0 CoreFoundation 0x0000000108ba9d85 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x000000010a7f9deb objc_exception_throw + 48
2 CoreFoundation 0x0000000108a87804 -[__NSArrayM objectAtIndex:] + 212
3 Votocast 0x0000000107dfd4de -[HomeView tableView:cellForRowAtIndexPath:] + 958
4 UIKit 0x000000010b6914f4 -[UITableView _createPreparedCellForGlobalRow:withIndexPath:willDisplay:] + 766
5 UIKit 0x000000010b69162c -[UITableView _createPreparedCellForGlobalRow:willDisplay:] + 74
6 UIKit 0x000000010b665c8a -[UITableView _updateVisibleCellsNow:isRecursive:] + 2799
7 UIKit 0x000000010b69a686 -[UITableView _performWithCachedTraitCollection:] + 92
8 UIKit 0x000000010b681344 -[UITableView layoutSubviews] + 224
9 UIKit 0x000000010b5ee980 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 703
10 QuartzCore 0x0000000109ff1c00 -[CALayer layoutSublayers] + 146
11 QuartzCore 0x0000000109fe608e _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 366
12 QuartzCore 0x0000000109fe5f0c _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24
13 QuartzCore 0x0000000109fda3c9 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 277
14 QuartzCore 0x000000010a008086 _ZN2CA11Transaction6commitEv + 486
15 UIKit 0x000000010b52e72e _UIApplicationHandleEventQueue + 7135
16 CoreFoundation 0x0000000108acf301 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
17 CoreFoundation 0x0000000108ac522c __CFRunLoopDoSources0 + 556
18 CoreFoundation 0x0000000108ac46e3 __CFRunLoopRun + 867
19 CoreFoundation 0x0000000108ac40f8 CFRunLoopRunSpecific + 488
20 GraphicsServices 0x000000010d4ebad2 GSEventRunModal + 161
21 UIKit 0x000000010b533f09 UIApplicationMain + 171
22 Votocast 0x0000000107e48d8f main + 111
23 libdyld.dylib 0x000000010cc0792d start + 1
24 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
In viewWillAppear, I remove all objects from this array and call webservice. But before I get response from webservice, app crashes to a line in cellForRowAtIndexPath. Your little help will be appreciated.
EDIT:
I have noticed that app only crashes when my tableview decelerationrate and I go to next screen and comeback to video listing screen. I have not done any type of code regarding decelerationration.
Clearly your datasource delegate isn't working properly. If you empty an array that is used by the datasource, then you must call reloadData. And when you get new data, you call reloadData again.
However, you shouldn't refresh data that way. You should display the old data until new data arrives.
You Clear all the object From Array in viewWillAppear Method But, do you Reload the tableview after that.
because this can cause the crash. you remove all the object but tableview tries to goto the last scrolled index. so it cause the crash.
Hope this will help You.
Thank you guys. I fixed it. I actually was allocating array in viewDidLoad and was just removing objects from that array in viewWillAppear. So I preserve my data and not calling webservice in viewWillAppear.
Related
I've read that other people have had similar uncaught exceptions, however most seem to be caused by a missing outlet connection. I don't believe mine is related to IBOutlets because the VC runs fine in most scenarios and so do my other VCs.
I think it has to do with Core Data. Here's the error, which I believe occurs in my table's cellForRowAtIndexPath:
2016-01-05 15:18:14.947 Do List[1476:81278] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<NSManagedObject 0x7fbb89e7cc50> valueForUndefinedKey:]: the entity TomTask is not key value coding-compliant for the key "completedDate".'
*** First throw call stack:
(
0 CoreFoundation 0x0000000102b5ee65 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x0000000104cfddeb objc_exception_throw + 48
2 CoreFoundation 0x0000000102b5eaa9 -[NSException raise] + 9
3 CoreData 0x0000000102757ec1 -[NSManagedObject valueForUndefinedKey:] + 289
4 Do List 0x000000010235b9d6 _TFC7Do_List24AllocationViewController9tableViewfS0_FTCSo11UITableView21cellForRowAtIndexPathCSo11NSIndexPath_CSo15UITableViewCell + 2630
5 Do List 0x000000010235c24f _TToFC7Do_List24AllocationViewController9tableViewfS0_FTCSo11UITableView21cellForRowAtIndexPathCSo11NSIndexPath_CSo15UITableViewCell + 79
6 UIKit 0x0000000103933e43 -[UITableView _createPreparedCellForGlobalRow:withIndexPath:willDisplay:] + 766
7 UIKit 0x0000000103933f7b -[UITableView _createPreparedCellForGlobalRow:willDisplay:] + 74
8 UIKit 0x0000000103908a39 -[UITableView _updateVisibleCellsNow:isRecursive:] + 2996
9 UIKit 0x000000010393d01c -[UITableView _performWithCachedTraitCollection:] + 92
10 UIKit 0x0000000103923edc -[UITableView layoutSubviews] + 224
11 UIKit 0x00000001038914a3 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 703
12 QuartzCore 0x000000010369659a -[CALayer layoutSublayers] + 146
13 QuartzCore 0x000000010368ae70 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 366
14 QuartzCore 0x000000010368acee _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24
15 QuartzCore 0x000000010367f475 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 277
16 QuartzCore 0x00000001036acc0a _ZN2CA11Transaction6commitEv + 486
17 UIKit 0x00000001037d4f7c _UIApplicationHandleEventQueue + 7329
18 CoreFoundation 0x0000000102a8aa31 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
19 CoreFoundation 0x0000000102a8095c __CFRunLoopDoSources0 + 556
20 CoreFoundation 0x0000000102a7fe13 __CFRunLoopRun + 867
21 CoreFoundation 0x0000000102a7f828 CFRunLoopRunSpecific + 488
22 GraphicsServices 0x0000000106bb7ad2 GSEventRunModal + 161
23 UIKit 0x00000001037da610 UIApplicationMain + 171
24 Do List 0x0000000102368fad main + 109
25 libdyld.dylib 0x000000010a52392d start + 1
26 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
A Few Notes
There's a particular set of VCs that, if run in a particular order, cause this error.
The error occurs when I go from A -> B -> C, then try to unwind to A.
If you look at the exception stack above, the error is happening in the cellForRowAtIndexPath of the allocViewController. That VC is B ,so it shouldn't be loading, just being unwound through.
It references "CompletedDate" which is the new thing I added yesterday that kick this whole thing off. CompletedDate was an existing CoreData attribute which I just started showing in view controller C.
If you look at the first line of the error, it looks like you have a class called TomTask which you're trying to use the "completedDate" from, but there isn't a "completedDate" in TomTask.
It appears (from entry #4 in your call stack) you're trying to do this in your tableView:cellForRowAtIndexPath: method of that view controller.
The application I work on is displaying a CollectionView in form of a calendar.
To simplify that we used the MSCollectionViewCalendarLayout from github.
Now it comes with multiple additional decoration views like a red line, which represents the current time in the calendar.
In our implementation there is also the possibility of filtering for different types, so the calendar not always displays the same kind/amount of cells. Unfortunately sometimes the application crashes just out of nowhere, when it should display the red timeline:
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'request for layout attributes for decoration view of kind MSCollectionElementKindCurrentTimeHorizontalGridline in section 0 when there are only 0 sections in the collection view'
*** First throw call stack:
(
0 CoreFoundation 0x034761e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x02fcb8e5 objc_exception_throw + 44
2 CoreFoundation 0x03476048 +[NSException raise:format:arguments:] + 136
3 Foundation 0x00e2f4de -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 116
4 UIKit 0x018eb290 -[UICollectionViewData layoutAttributesForDecorationViewOfKind:atIndexPath:] + 228
5 UIKit 0x018b5764 -[UICollectionView _dequeueReusableViewOfKind:withIdentifier:forIndexPath:viewCategory:] + 242
6 UIKit 0x018a8036 -[UICollectionView _createPreparedSupplementaryViewForElementOfKind:atIndexPath:withLayoutAttributes:applyAttributes:] + 381
7 UIKit 0x018a9775 -[UICollectionView _updateVisibleCellsNow:] + 4730
8 UIKit 0x018ad65f -[UICollectionView layoutSubviews] + 265
9 UIKit 0x012d0964 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 355
10 libobjc.A.dylib 0x02fdd82b -[NSObject performSelector:withObject:] + 70
11 QuartzCore 0x026a445a -[CALayer layoutSublayers] + 148
12 QuartzCore 0x02698244 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 380
13 QuartzCore 0x026980b0 _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 26
14 QuartzCore 0x025fe7fa _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 294
15 QuartzCore 0x025ffb85 _ZN2CA11Transaction6commitEv + 393
16 QuartzCore 0x02600258 _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 92
17 CoreFoundation 0x0343e36e __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 30
18 CoreFoundation 0x0343e2bf __CFRunLoopDoObservers + 399
19 CoreFoundation 0x0341c254 __CFRunLoopRun + 1076
20 CoreFoundation 0x0341b9d3 CFRunLoopRunSpecific + 467
21 CoreFoundation 0x0341b7eb CFRunLoopRunInMode + 123
22 GraphicsServices 0x049615ee GSEventRunModal + 192
23 GraphicsServices 0x0496142b GSEventRun + 104
24 UIKit 0x01261f9b UIApplicationMain + 1225
25 CariAudit 0x001036ad main + 141
26 libdyld.dylib 0x039d9701 start + 1
27 ??? 0x00000003 0x0 + 3
)
libc++abi.dylib: terminating with uncaught exception of type NSException
Now I know that with this custom layout, many people get this error message when they change the underlying data of the collectionView and the solution to this is to call "invalidateLayoutCache" on the layout. The only problem is that I already have that in my code and it gets called before calling reloadData on the collectionView.
Does anyone maybe have an idea/approach for solving this kind of problem?
Thanks
After hours of searching I finally managed to find the error.
The problem was that the MSCollectionViewCalendarLayout missed to empty the Attributes-Dictionaries
currentTimeIndicatorAttributes and currentTimeHorizontalGridlineAttributes.
To fix the error all I had to do was to expand the invalidateLayoutCache method with the following:
[self.currentTimeIndicatorAttributes removeAllObjects];
[self.currentTimeHorizontalGridlineAttributes removeAllObjects];
What i have Done?
In one of my UIViewController child i have implemented UITableView and have implemented the necessary UITableViewDelegate functions.
What i am Facing?
The issue i am facing is that i get EXC_BAD_ACCESS in Application whenever i relaunch the Controller and tap on Any cell.
What i have Tried?
I have tried to place breakpoints in the function didDeselectRowAtIndexPath: but it never reaches the Breakpoint. I tried Global Exception Breakpoint but it also didn't worked. I checked using the Instruments and found that a zombie is detechted when didDeselectRowAtIndexPath is called but control doesn't reaches the Function.
Instruments Zombie Details Image - Photo Bucket Link
After Implementing the Given Suggestions in the Comments this is the log that i have received
*** -[__NSArrayM insertObject:atIndex:]: object cannot be nil'
*** First throw call stack:
(
0 CoreFoundation 0x023e11e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x01fc98e5 objc_exception_throw + 44
2 CoreFoundation 0x02393abc -[__NSArrayM insertObject:atIndex:] + 844
3 CoreFoundation 0x02393760 -[__NSArrayM addObject:] + 64
4 UIKit 0x00bf5782 -[UITableViewIndex _displayTitles] + 1071
5 UIKit 0x00bf58a8 -[UITableViewIndex _cacheAndMeasureTitles] + 171
6 UIKit 0x00bf6213 -[UITableViewIndex sizeThatFits:] + 131
7 UIKit 0x00a18bbc -[UITableView _updateIndexFrameSuppressingChangeNotification:] + 513
8 UIKit 0x00a189b6 -[UITableView _updateIndexFrame] + 41
9 UIKit 0x00a19a5f -[UITableView _updateIndex] + 649
10 UIKit 0x00a336f7 -[UITableView layoutSubviews] + 295
11 UIKit 0x009b3964 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 355
12 libobjc.A.dylib 0x01fdb82b -[NSObject performSelector:withObject:] + 70
13 QuartzCore 0x002ba45a -[CALayer layoutSublayers] + 148
14 QuartzCore 0x002ae244 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 380
15 QuartzCore 0x002ae0b0 _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 26
16 QuartzCore 0x002147fa _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 294
17 QuartzCore 0x00215b85 _ZN2CA11Transaction6commitEv + 393
18 QuartzCore 0x00216258 _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 92
19 CoreFoundation 0x023a936e __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 30
20 CoreFoundation 0x023a92bf __CFRunLoopDoObservers + 399
21 CoreFoundation 0x02387254 __CFRunLoopRun + 1076
22 CoreFoundation 0x023869d3 CFRunLoopRunSpecific + 467
23 CoreFoundation 0x023867eb CFRunLoopRunInMode + 123
24 GraphicsServices 0x0381a5ee GSEventRunModal + 192
25 GraphicsServices 0x0381a42b GSEventRun + 104
26 UIKit 0x00944f9b UIApplicationMain + 1225
27 MyApplication 0x00001f9c main + 76
28 libdyld.dylib 0x034b3701 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
It is pretty clear from all the logs and Zombie images that you are accessing the deallocated CountryListViewController. Keep track on the CountryListViewController and check it is available while you processing your table-view operations.
The better option is, Go to Xcode Menu Product->Scheme->Mange Schemes->Edit (left bottom)-> Debug-> Diagnostics -> Check all the options -> then Run the project.
This will be the Lighthouse to discover your crash.
Attempting to remove an object at a NSMutableArray causes a crash:
2014-03-07 18:58:03.755 HomeWork Pro +[12637:70b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayI removeObjectAtIndex:]: unrecognized selector sent to instance 0xa2f4c20'
remove object code:
[hwArray removeObjectAtIndex:self.indexPath.row];
This only happens if I do it with self.indexPath.row, if I do it with a number it functions normally. I know the self.indexPath.row is not nil, I've NSlogged it to be sure and it turnde right. After doing that I do
[table reloadData]
to reload the UITableView data and the methods.
Any clue on what's the issue here?
Call stack
*** First throw call stack:
(
0 CoreFoundation 0x017aa5e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x0152d8b6 objc_exception_throw + 44
2 CoreFoundation 0x01847903 -[NSObject(NSObject) doesNotRecognizeSelector:] + 275
3 CoreFoundation 0x0179a90b ___forwarding___ + 1019
4 CoreFoundation 0x0179a4ee _CF_forwarding_prep_0 + 14
5 HomeWork Pro + 0x00006c88 -[HomeWork SelfDelete] + 216
6 HomeWork Pro + 0x0000711a -[HomeWork done:] + 618
7 libobjc.A.dylib 0x0153f874 -[NSObject performSelector:withObject:withObject:] + 77
8 UIKit 0x0029d0c2 -[UIApplication sendAction:to:from:forEvent:] + 108
9 UIKit 0x0029d04e -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 61
10 UIKit 0x003950c1 -[UIControl sendAction:to:forEvent:] + 66
11 UIKit 0x00395484 -[UIControl _sendActionsForEvents:withEvent:] + 577
12 UIKit 0x00394733 -[UIControl touchesEnded:withEvent:] + 641
13 UIKit 0x002da51d -[UIWindow _sendTouchesForEvent:] + 852
14 UIKit 0x002db184 -[UIWindow sendEvent:] + 1232
15 UIKit 0x002aee86 -[UIApplication sendEvent:] + 242
16 UIKit 0x0029918f _UIApplicationHandleEventQueue + 11421
17 CoreFoundation 0x0173383f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
18 CoreFoundation 0x017331cb __CFRunLoopDoSources0 + 235
19 CoreFoundation 0x0175029e __CFRunLoopRun + 910
20 CoreFoundation 0x0174fac3 CFRunLoopRunSpecific + 467
21 CoreFoundation 0x0174f8db CFRunLoopRunInMode + 123
22 GraphicsServices 0x023349e2 GSEventRunModal + 192
23 GraphicsServices 0x02334809 GSEventRun + 104
24 UIKit 0x0029bd3b UIApplicationMain + 1225
25 HomeWork Pro + 0x00008bad main + 141
26 libdyld.dylib 0x02c8a70d start + 1
27 ??? 0x00000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
It looks to me like the crash message you posted and your stack trace do not match. The stack trace shows an "unrecognized selector" crash in the making, but the crash message shows that you were attempting to insert a nil object into an array.
Neither of those things matches the line of code that you posted. (removing an object from an array.) I guess you could get an unrecognized selector error from the line of source you posted if the array wasn't really a mutable array...
EDIT:
Based on your updated question, it's clear. Your array is not actually a mutable array even though you think it is.
Post the code that creates the array.
If you're copying it somewhere, look at that code carefully. If you're loading it from a plist or an archive, be aware that mutable arrays come back as immutable when you read them back in.
What you have is an immutable NSArray. What you want is an NSMutableArray, which actually does implement removeObjectAtIndex:. Make sure your array isn't getting replaced with an immutable version at some point.
Hey can anyone help me out that what type of exception is this i had earlier a code and link is as: Application run on simulator but not on device in iphone
can anybody here who can tell that what type of exception is in it? is there any memory leak?
here is the log below:
2013-12-27 17:53:26.814 Skirr[1346:a0b] Application windows are expected to have a root view controller at the end of application launch
2013-12-27 17:53:27.995 Skirr[1346:a0b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSPlaceholderArray initWithObjects:count:]: attempt to insert nil object from objects[0]'
*** First throw call stack:
(
0 CoreFoundation 0x032745e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x021b88b6 objc_exception_throw + 44
2 CoreFoundation 0x03228316 -[__NSPlaceholderArray initWithObjects:count:] + 390
3 CoreFoundation 0x0324bce9 +[NSArray arrayWithObject:] + 73
4 Skirr 0x000093bd -[SlideViewController viewDidLoad] + 1597
5 UIKit 0x00e2d318 -[UIViewController loadViewIfRequired] + 696
6 UIKit 0x00e2d5b4 -[UIViewController view] + 35
7 UIKit 0x00e473e2 -[UINavigationController _startCustomTransition:] + 778
8 UIKit 0x00e540c7 -[UINavigationController _startDeferredTransitionIfNeeded:] + 688
9 UIKit 0x00e54cb9 -[UINavigationController __viewWillLayoutSubviews] + 57
10 UIKit 0x00f8e181 -[UILayoutContainerView layoutSubviews] + 213
11 UIKit 0x00d84267 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 355
12 libobjc.A.dylib 0x021ca81f -[NSObject performSelector:withObject:] + 70
13 QuartzCore 0x005622ea -[CALayer layoutSublayers] + 148
14 QuartzCore 0x005560d4 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 380
15 QuartzCore 0x00555f40 _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 26
16 QuartzCore 0x004bdae6 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 294
17 QuartzCore 0x004bee71 _ZN2CA11Transaction6commitEv + 393
18 QuartzCore 0x004bf544 _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 92
19 CoreFoundation 0x0323c4ce __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 30
20 CoreFoundation 0x0323c41f __CFRunLoopDoObservers + 399
21 CoreFoundation 0x0321a344 __CFRunLoopRun + 1076
22 CoreFoundation 0x03219ac3 CFRunLoopRunSpecific + 467
23 CoreFoundation 0x032198db CFRunLoopRunInMode + 123
24 GraphicsServices 0x034ce9e2 GSEventRunModal + 192
25 GraphicsServices 0x034ce809 GSEventRun + 104
26 UIKit 0x00d19d3b UIApplicationMain + 1225
27 Skirr 0x000055a2 main + 130
28 libdyld.dylib 0x06896725 start + 0
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
have look at this link from
attempt to insert nil object from objects[0]
you are inserting or handling nil object you can get that line refer given above link
The error
* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '* -[__NSPlaceholderArray initWithObjects:count:]: attempt to insert nil object from objects[0]'
is occurring because you are trying to add nil value to an NSArray. After looking through your code on the other question the specific line of code that it is crashing on is
[_slideNavigationController setViewControllers:[NSArray arrayWithObject:initalViewController] animated:NO];
It is crashing here because of one of two things
1) initalViewController is nil so when you add it using arrayWithObject it crashes.
or
2) setViewControllers:[NSArray arrayWithObject:initalViewController] is causing the error because [NSArray arrayWithObject:initalViewController] is setting nil to the method setViewControllers: method which takes an NSArray.
I would say it is option (1) that is causing your issue though as the crash happens when arrayWithObject is called.
Check your main.m. The last argument should be set to the name of the class that implements the UIApplicationDelegate protocol OR you can try for last argument like NSStringFromClass([AppDelegate class]).
Please check this link it might help you .
click here