iOS: Terminating application due to uncaught exception 'NSRangeException' -
i have searched through number of these nsrangeexception
error threads can't seem find answer question. here error:
2015-08-15 17:28:43.793 utk recruiting[8794:254203] * terminating app due uncaught exception 'nsrangeexception', reason: '* -[__nsarrayi objectatindex:]: index 3 beyond bounds [0 .. 2]' *** first throw call stack:
here couple of bits of code. going through documents directories, getting filenames , paths, , i'm trying populate uitableview
filenames cell can selected, , file can attached email. here few bits of code:
parses documents directory, puts csv files in corresponding arrays.
- (void) refreshtable { nsarray *paths = nssearchpathfordirectoriesindomains(nsdocumentdirectory, nsuserdomainmask, yes); nsstring *documentsdirectory = [paths objectatindex:0]; nsarray *documentarray = [[nsfilemanager defaultmanager] contentsofdirectoryatpath:documentsdirectory error:nil]; nsarray *csvfiles = [documentarray filteredarrayusingpredicate:[nspredicate predicatewithblock:^bool(nsstring *evaluatedobject, nsdictionary *bindings) { return [evaluatedobject hassuffix:@".csv"]; }]]; self.csvfilenames = (nsmutablearray*) csvfiles; self.csvfilepaths = [nsmutablearray arraywithcapacity:[csvfiles count]]; (nsstring *filename in csvfiles) { [self.csvfilepaths addobject:[documentsdirectory stringbyappendingpathcomponent:filename]]; } nslog(@"files array %@", _csvfilenames); nslog(@"files array %@", _csvfilepaths);
this uitableview code:
- (nsinteger)numberofsectionsintableview:(uitableview *)tableview { // return number of sections. return 1; } - (nsinteger)tableview:(uitableview *)tableview numberofrowsinsection:(nsinteger)section { // return number of rows in section. nslog(@"count: %lu", (unsigned long)[self.csvfilenames count]); return [self.csvfilenames count]; } -(uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath { static nsstring *cellidentifier = @"cell"; uitableviewcell *cell = [tableview dequeuereusablecellwithidentifier:cellidentifier forindexpath:indexpath]; cell.textlabel.text=[self.csvfilenames objectatindex:indexpath.row]; return cell; }
after placing break points throughout code, i've found crashes in cellforrowatindexpath
method, last method in code posted. cellforrowatindexpath method not run @ all. else important note there 4 csv files, , [self.csvfilenames count]
correctly gives number 4.
the code should running until index 3, can't figure out why not.
bt crash report:
thread #1: tid = 0x56469, 0x0000000109200286 >libsystem_kernel.dylib
__pthread_kill + 10, queue = 'com.apple.main-thread', stop >reason = signal sigabrt frame #0: 0x0000000109200286 libsystem_kernel.dylib
__pthread_kill + 10 frame #1: 0x000000010923342f libsystem_pthread.dylibpthread_kill + 90 frame #2: 0x0000000108fa019a libsystem_sim_c.dylib
abort + 129 frame #3: 0x0000000108d8b481 libc++abi.dylibabort_message + 257 frame #4: 0x0000000108db33d5 libc++abi.dylib
default_terminate_handler() + 267 frame #5: 0x0000000101e4be19 libobjc.a.dylib_objc_terminate() + 103 frame #6: 0x0000000108db0b01 libc++abi.dylib
std::__terminate(void (*)()) + 8 frame #7: 0x0000000108db07aa libc++abi.dylib__cxa_rethrow + 99 frame #8: 0x0000000101e4bd2c libobjc.a.dylib
objc_exception_rethrow + 40 frame #9: 0x00000001020db41e corefoundationcfrunlooprunspecific + 654 frame #10: 0x0000000104e74a3e graphicsservices
gseventrunmodal + 161 frame #11: 0x00000001025ab8c0 uikit`uiapplicationmain + 1282
- frame #12: 0x000000010176311f utk recruiting
main(argc=1, argv=0x00007fff5e4a04f8) + 111 @ main.m:14 frame #13: 0x0000000108ef8145 libdyld.dylib
start + 1 frame #14: 0x0000000108ef8145 libdyld.dylib`start + 1thread #2: tid = 0x564a0, 0x0000000109201232 libsystem_kernel.dylib
kevent64 + 10, queue = 'com.apple.libdispatch-manager' frame #0: 0x0000000109201232 libsystem_kernel.dylib
kevent64 + 10 frame #1: 0x0000000108eb376c libdispatch.dylib_dispatch_mgr_invoke + 247 frame #2: 0x0000000108eb3511 libdispatch.dylib
_dispatch_mgr_thread + 54thread #3: tid = 0x564a2, 0x000000010920094a libsystem_kernel.dylib
__workq_kernreturn + 10 frame #0: 0x000000010920094a libsystem_kernel.dylib
__workq_kernreturn + 10 frame #1: 0x00000001092316c3 libsystem_pthread.dylib_pthread_wqthread + 869 frame #2: 0x000000010922f40d libsystem_pthread.dylib
start_wqthread + 13thread #4: tid = 0x564a3, 0x000000010920094a libsystem_kernel.dylib
__workq_kernreturn + 10 frame #0: 0x000000010920094a libsystem_kernel.dylib
__workq_kernreturn + 10 frame #1: 0x00000001092316c3 libsystem_pthread.dylib_pthread_wqthread + 869 frame #2: 0x000000010922f40d libsystem_pthread.dylib
start_wqthread + 13thread #5: tid = 0x564a4, 0x000000010920094a libsystem_kernel.dylib
__workq_kernreturn + 10 frame #0: 0x000000010920094a libsystem_kernel.dylib
__workq_kernreturn + 10 frame #1: 0x00000001092316c3 libsystem_pthread.dylib_pthread_wqthread + 869 frame #2: 0x000000010922f40d libsystem_pthread.dylib
start_wqthread + 13thread #6: tid = 0x564a5, 0x000000010920094a libsystem_kernel.dylib
__workq_kernreturn + 10 frame #0: 0x000000010920094a libsystem_kernel.dylib
__workq_kernreturn + 10 frame #1: 0x00000001092316c3 libsystem_pthread.dylib_pthread_wqthread + 869 frame #2: 0x000000010922f40d libsystem_pthread.dylib
start_wqthread + 13
crashing in main.m on return statement:
int main(int argc, char * argv[]) { @autoreleasepool { return uiapplicationmain(argc, argv, nil, nsstringfromclass([appdelegate class])); } }
update: have been browsing many other nsrangeexception threads, far no luck.
if thinking uitableview
not call threads, call main thread only. try adding exceptional breakpoint in project shown in screenshot, stop right before crash happen. can find crashing line , identify issue happening
Comments
Post a Comment