[NSCFArray row]: unrecognized selector sent to instance 0x3953a20 - ios

I get a crash with this console message:
Terminating app due to uncaught exception
'NSInvalidArgumentException', reason: '*** -[NSCFArray row]:
unrecognized selector sent to instance 0x3953a20'
This happens when I scroll trough a table that gets its data from an array of dictionaries.

Look in the crash log's stack trace to see where exactly this call is happening.
If the variable you're sending -row to isn't actually typed as an NSArray, it's likely that you've failed to follow the memory management rules for that variable. These same symptoms are very commonly caused by that. Something that responds to -row could have existed at one point, been deallocated because you didn't -retain it, and then an NSArray was later allocated in that spot.
Run a "Build & Analyze," and re-re-review the memory management guidelines until you know them in your sleep.

Looks like you are sending a row message to an NSArray. There is no row method defined in the NSArray class. If you are using a table, my guess is you want to send "row" to the indexPath parameter to get the position and then get the data at that position in your data array:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
// first row will be like 0
NSUInteger row = [indexPath row];
// get the same row position in your data array
id data = [YOUR_DATA_ARRAY objectAtIndex:row];
}
That will give you the numeric position of the row. One caveat: "row" is not part of the base NSIndexPath class. It's added as a category in UIKit.

Related

IOS/Objective-C: Trace precise place of exception

I am getting an exception when I load a view controller. The error message suggests the program is trying to send length to NSNull as follows:
[NSNull length]: unrecognized selector sent to instance 0x3b1cda70
(lldb)
The last log statement prior to the exception is at the end of a method and from what I can tell although a value is null that it returns, this method is not the issue.
- (NSString *)pickerView:(UIPickerView *)pickerView
titleForRow:(NSInteger)row
forComponent:(NSInteger)component
{
NSLog(#"in titleforrow");
NSLog(#"about to return firsts[row]%#",firsts[row]);//this is null
return firsts[row];
}
This suggests the problem is in some other method. So I have put log statements before every use of length in the view controller class (all of which are in a save method that should not be called on loading) and, in fact, none of these log statements appear in the log suggesting that length is never sent.
Nonetheless, the program is throwing the exception. I tried adding an exception breakpoint as suggested in this answer
While it lets me view the threads, I still can't figure out what is throwing the exception.
Would appreciate any suggestions on where to go from here.

-[CLLocation length]: unrecognized selector after table display

Quite unexpectedly after doing some minor modifications, my code has started crashing with:
-[CLLocation length]: unrecognized selector sent to instance 0x1b3739c0.
This happens after the app has completed the display of the cells of a table, more precisely after exiting:
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
I tried putting breakpoints in all length accesses in the code, but none of them was caught. I also set a breakpoint on [NSObject(NSObject) doesNotRecognizeSelector:] and this in fact was caught, but gave no information altogether. I also investigated the crash log but the last contact of the crashing thread with my app was in the main function. How may I discover the point of the program producing the crash?
CLLocation does not have a length method, see docs. If it's not your code (you seemed to imply that), maybe it's something in one of your dependencies?
Btw, you should add an exception breakpoint, it should catch that.
In fact one the table textfields was incorrectly a CLLocation. The only catch was the timing of the error. Thank you everyone.

Zero object in array crashes the program, also after certain count

I have a program that grabs data from Instagram, puts it into dictionary and then I parse it.
Problems begin when I try to use that data, magically item number 0 crashes my program.
Also, after certain number next item also crashes the program.
Here is the code for UITableViewCell, that grabs text from the array/dictionaries and puts it into cell. As it looks, it crashes, if I add another check to start with number 1, it works, but crashes later when it reaches some count.
I don't understand why this happens, since I have the method that tells the TableView how many rows are in table, and it returns [self.loader.dataArray count], so it can't possibly try to load the thing that is out of bounds.
if (self.loader.dataArray[indexPath.row] != nil )
{
cell.textLabel.text = [[[self.loader.dataArray[indexPath.row] objectForKey:#"caption"] objectForKey:#"from"] objectForKey:#"full_name"];
}
Here is the error I am getting:
instagramClient[8254:907] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSNull objectForKey:]: unrecognized selector sent to instance 0x3bb8f090'
The exception that you're getting does not indicate an out of bounds issue, it indicates that you have got an NSNull in your dataArray (or possibly in the "caption" object of one of the dictionaries in your dataArray or in the "from" object of one of those dictionaries, and so on). Try logging all of self.loader.dataArray when you get updates to that array and see if it contains any NSNull objects.

Saving another type to an attribute of an entity to core data?

cell.textLabel.text = operationEnt.operationNaam;
on this line of code I get the error:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString operationNaam]: unrecognized selector sent to instance 0x6bce400'
But operationNaam is an attribute defined as a String. So I'm wondering, where is my mistake.
This is when I try to fill my cells of my TableView.
That exception means that the message operationNaam is being sent to a NSString object, and NSString does not recognize that message selector.
This means that your operationEnt object has somehow become a NSString during runtime.
Possibly, you did this...
operationEnt = someString;
when you meant this...
operationEnt.operationNaam = someString;
It seems that you either have memory management issues or misunderstand Objective-C's property accessor syntax.o operationEnt keeps becoming an NSString which doesn't respond to that particular property getter message, hence the crash. (Watch out for overreleases!)

Serialization array of custom objects iOS

I know there is a lot of resources about that here but yet, I can't find what's going wrong with my code:
I have a class Level and two subclasses of Level: GameLevel and TransitionLevel. Each of this class implements the NSCoding protocol.
Then, I've got an array of Level (so it contains both classes of GameLevel and TransitionLevel). Saving the archive seems to work fine :
NSString *archivePath = [DOCUMENT_DIRECTORY stringByAppendingPathComponent:#"levels.archive"];
[NSKeyedArchiver archiveRootObject:levels toFile:archivePath];
Note that levels is the array I want to save. I can see the file, it's created and seems to contains what it's supposed to contain.
But when I want to retrieve this array :
NSString *archivePath = [DOCUMENT_DIRECTORY stringByAppendingPathComponent:#"levels.archive"];
levels = [NSKeyedUnarchiver unarchiveObjectWithFile:archivePath];
I've got this exception:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSArrayM insertObject:atIndex:]: object cannot be nil'
I'm not sure what I'm missing here.
Either your implementation of initWithCoder: returns nil, either some part of your code tries to insert a nil value into an array.
You may go in the Breakpoint Navigator (⌘6) and add an Exception Breakpoint. Then, when the application raises an exception, the Debug Navigator will display the stack of the functions and methods currently executed. This would allow you to know precisely which method is trying to insert nil into an array.

Resources