I'm trying to put some data in the database. I'm using the following code also in other views. There does it work. But on this view it doesn't work. You can see the code below.
- (void)fetchKlassementIntoDocument:(UIManagedDocument *)document
{
NSLog(#"log");
dispatch_queue_t fetchKlassement = dispatch_queue_create("klassement fetcher", NULL);
dispatch_async(fetchKlassement, ^{
NSLog(#"Log2");
NSLog(#"log3");
NSArray *klassement = [GenkData getRanking];
[document.managedObjectContext performBlock:^{
NSLog(#"klassement array %#",klassement);
for (NSDictionary *genkInfo in klassement ) {
[Klassement klassementWithGenkInfo:genkInfo inManagedObjectContext:document.managedObjectContext];
NSLog(#"inserted klassement");
}
NSLog(#"Log4");
[document saveToURL:document.fileURL forSaveOperation:UIDocumentSaveForOverwriting completionHandler:NULL];
NSLog(#"Log5");
NSLog(#"Log 6");
}];
});
NSLog(#"Log7");
dispatch_release(fetchKlassement);
NSLog(#"Log8");
}
This gives the following error log.
2012-10-25 10:50:07.527 RacingGenk[17989:907] log
2012-10-25 10:50:07.528 RacingGenk[17989:907] Log7
2012-10-25 10:50:07.529 RacingGenk[17989:907] Log8
2012-10-25 10:50:07.531 RacingGenk[17989:4f03] Log2
2012-10-25 10:50:07.532 RacingGenk[17989:4f03] log3
2012-10-25 10:50:07.604 RacingGenk[17989:907] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayI objectAtIndex:]: index 0 beyond bounds for empty array'
After fetching the data I fill up a tableview with this data. I think that's why the error came up. But can somebody say me what is going wrong ?
Kind regards.
The line from your code:
NSArray *klassement = [GenkData getRanking];
Check the getRanking method & the klassement Array. The crash is occurring due to this line only.
Put a log for both. Hope it'll resolve your issue.
Related
Whenever I insert an NSString return from a view into the UITableView's data source, when the call to insert the new cell is placed, the program crashes. Below is the code:
- (void)insertTableObject:(NSString *)thing
{
if (!locations) locations = [[NSMutableArray alloc] init];
[locations addObject:[NSString stringWithFormat:#"%#", thing]];
NSLog(#"%#", locations);
self.tableContents = [[NSMutableDictionary alloc] initWithObjectsAndKeys:locations,#"", nil];
self.sortedKeys =[[self.tableContents allKeys] sortedArrayUsingSelector:#selector(compare:)];
[self.tableView insertRowsAtIndexPaths:#[[NSIndexPath indexPathForRow:([locations count]-1) inSection:0]] withRowAnimation:UITableViewRowAnimationAutomatic];
}
Below is the array printed out, and the accompanying error that takes place:
2013-03-23 15:06:32.433 XXX[9149:907] (
"D.C",
la
)
2013-03-23 15:06:32.439 XXX[9149:907] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 1 beyond bounds [0 .. 0]'
*** First throw call stack:
(0x320852a3 0x39f1b97f 0x31fd0b75 0xc05bd 0x33ed854d 0x33ec9685 0x33ec5d55 0x33ec4d27 0x33ec1bf9 0x33ff6b27 0xbeceb 0xf6413 0x33f780c5 0x33f78077 0x33f78055 0x33f7790b 0x33f77e01 0x33ea05f1 0x33e8d801 0x33e8d11b 0x35b815a3 0x35b811d3 0x3205a173 0x3205a117 0x32058f99 0x31fcbebd 0x31fcbd49 0x35b802eb 0x33ee1301 0xb701b 0xb6f70)
libc++abi.dylib: terminate called throwing an exception
Is it a problem that "la" is printing without quotes? Could the system potentially not be seeing that entry?
I ended up solving the problem. I had cells with detail views, so when it would draw the detailView index, it wasn't present. I added a simple line to the function in the original post to add another value to the detailView array.
I have been trying to work through a bug for many hours in my iOS App involving rangeOfString and have finally been able to track down where my app crashes. My app sets TextViewA to the first half of my MainTextView. What if statement should be added should be added to check for nil?
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSCFString rangeOfString:options:range:locale:]: nil argument'
*** First throw call stack:
.
[[myViewController tvTextFirstHalf] setText:[[mainTextView.text componentsSeparatedByString:[[myViewController tvTextMiddle]text]] objectAtIndex:0]];
..............................................................................................
No memory available to program now: unsafe to call malloc
2013-01-04 14:30:58.138 Type[7279:c07] separator: (null)
2013-01-04 14:30:58.138 Type[7279:c07] mainTextView: ; layer = ; contentOffset: {0, 0}
>
2013-01-04 14:30:58.139 Type[7279:c07] mainTextView.text: TESTTTTTTTT f f.
2013-01-04 14:30:58.142 Type[7279:c07] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '* -[__NSCFString rangeOfString:options:range:locale:]: nil argument'
* First throw call stack:
(0x1a5d012 0x1882e7e 0x1a5cdeb 0xf78688 0xf87d88 0xfd05df 0x165ec 0x15dc6 0x1fd7b 0x56d8d5 0x56db3d 0xf74e83 0x1a1c376 0x1a1be06 0x1a03a82 0x1a02f44 0x1a02e1b 0x221d7e3 0x221d668 0x4be65c 0x2c5d 0x2b85)
libc++abi.dylib: terminate called throwing an exception
(gdb)
This oneliners are not considered a good practice in obj-C (i know, it's arguable).
Try to break:
[[myViewController tvTextFirstHalf] setText:[[mainTextView.text componentsSeparatedByString:[[myViewController tvTextMiddle]text]] objectAtIndex:0]];
Into some more debugging-friendly code:
NSString *separator = [[myViewController tvTextMiddle]text];
NSLog (#"separator: %#", separator);
NSLog (#"mainTextView: %#",mainTextView); //is this one nil?
NSLog (#"myViewController.tvTextMiddle: %#", myViewController.tvTextMiddle); //what about this one??
NSLog (#"mainTextView.text: %#",mainTextView.text);
NSArray *components = [mainTextView.text componentsSeparatedByString:separator];
NSLog (#"we found %d components", components.count);
NSString *result = (NSString *)[components objectAtIndex:0];
NSLog (#"result should be: %#", result);
[[myViewController tvTextFirstHalf] setText:result];
The code will break ofcourse but at least you'll know where the problem lies.
You could change last four lines then in something like:
if (components.count >= 1)
{
NSString *result = (NSString *)[components objectAtIndex:0];
NSLog (#"result should be: %#", result);
[[myViewController tvTextFirstHalf] setText:result];
}
else
{
[[myViewController tvTextFirstHalf] setText:#"empty!"];
}
EDIT:
From the NSLog you posted it is obvious that your separator [[myViewController tvTextMiddle]text] is null. Note that null is not the same as empty string. It is unallocated string.
My guess is that actually your tvTextMiddle is null (or if you are using XIB files it is not properly connected to the IBOutlet).
You can check that by adding (somewhere before the breaking-line):
NSLog (#"myViewController.tvTextMiddle: %#", myViewController.tvTextMiddle);
The crash is due to this call componentsSeparatedByString.
If your textview is nil or no text then crash'll occur.
So add a condition like:
if(mainTextView.text.length != 0 && [myViewController tvTextMiddle]text].length != 0)
{
[[myViewController tvTextFirstHalf] setText:[[mainTextView.text componentsSeparatedByString:[[myViewController tvTextMiddle]text]] objectAtIndex:0]];
}
I have an iOS App that I just submitted an update for. The development version of the app (simulator and my 4S) never crashed and it works just fine. The app got approved today as well as the IAP, but I realized this morning that the iAP was not "cleared for purchase". I just cleared it for purchase, but the app still crashes. The error the iPhone gives (running the app store version) gives the error:
<Error>: *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayI objectAtIndex:]: index 0 beyond bounds for empty array'
Here is the code where that happens:
- (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:
(SKProductsResponse *)response
{
NSArray *myProduct = response.products;
//this line is where the error occurs
noAdProduct = [myProduct objectAtIndex:0];
if (![[[NSUserDefaults standardUserDefaults] objectForKey:#"the id here"] boolValue]) {
adCell.detailTextLabel.text = [NSString stringWithFormat:#"$%#", noAdProduct.price];
adCell.userInteractionEnabled = YES;
adCell.accessoryType = UITableViewCellAccessoryNone;
adCell.accessoryView = nil;
[self.tableView reloadData];
}
}
This happens while requesting a list of available products, which obviously returns the product in the simulator but not in the app. I just added a safeguard against this but I will need to submit it to the App Store again.
Does anyone know why the iAP is not showing up for the App Store version? Do I need to wait for the "cleared for sale" option to go to Apple's servers? Thanks!
Obviously myProduct array is empty. Why this happens is another question, but you should never call objectAtIndex without making sure the requested index exists.
if ([myProduct count] > 0)
noAdProduct = [myProduct objectAtIndex:0];
else
// Deal with the situation when the array is empty.
I am writing an iPad app. I load a view in with "initWithNibName" and then trying to push the view onto the Navigation controller.
[self.navigationController pushViewController:tvc animated:YES];
This causes the app to crash giving the following stackTrace
2011-09-01 12:46:06.040 PuckDragDemo[4932:f803] * Terminating app due to uncaught exception 'NSRangeException', reason: '* -[__NSArrayM objectAtIndex:]: index 0 beyond bounds for empty array'
* First throw call stack:
(0x1191062 0x1322d0a 0x117ddc8 0x2979 0xae95 0x449ebe 0x44a1b1 0x45bccd 0x45bebf 0x45c18b 0x45cc2f 0x45d1d6 0x45cdf4 0x13975 0x1192ed9 0x386eb2 0x386e4a 0x42c3e6 0x42c8af 0x42bb6e 0x3ac2a0 0x3ac4c6 0x392c74 0x386399 0x1d87fa9 0x11651d5 0x10ca042 0x10c892a 0x10c7dd4 0x10c7ceb 0x1d86879 0x1d8693e 0x38438b 0x1c49 0x1bc5)
terminate called throwing an exception(gdb) bt
I have no idea why I am getting this error when I don't have an array. my only guess is that there is an array in the background somewhere which is getting called?
P.S the code requested
if (self.started == YES) return;
if (self.bEditMode == YES) {
[self go];
} else {
GetReadyModalViewController *modalVC = [[GetReadyModalViewController alloc] initWithNibName:#"GetReadyModelViewController" bundle:nil];
modalVC.delegate = self;
[self presentModalViewController:modalVC animated:NO];
modalVC.taskTitle.text = [self.taskPreferences objectForKey:#"title"];
modalVC.taskDescription.text = [self.taskPreferences objectForKey:#"description"];
}
}
It is irrelevant to the pushing on the navigationController, it is a problem inside of the tic viewController. Please post the code from the viewDidLoad/viewWillAppear, as your are instantiating an array and trying to get data from it [myMutableArray objectAtIndex:**0**]
Fixed it. I don't know exactly how it worked. There is a array in my code but not directly connected to the navigation controller. It appears that a index in the array was being called that didn't exist but for some reason it wasn't calling an error. Don't ask me why but when the navigation controller pushed the view it picked up on a previous undetected error.
I am trying to build an iPhone app. But at the time of compiling there is a message showing that
[Session started at 2009-01-29 18:25:40 +0600.]
2009-01-29 18:25:44.238 SimpleGame[3691:20b] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[NSCFArray objectAtIndex:]: index (1) beyond bounds (0)'
2009-01-29 18:25:44.247 SimpleGame[3691:20b] Stack: ( .........
Actually when I do active these code then this message is shown, code are:
NSMutableArray *todoArray = [[NSMutableArray alloc] init];
self.todos = todoArray;
[todoArray release];
How can I overcome this problem?
It seems like you're trying to access outside the bounds of an empty array.
put breakpoints on objc_exception_throw and [NSException raise]. This should show the error before it's actually thrown and should hopefully tell you enough to find the problem.
Tony