UILabel error - [__NSCFNumber string]: unrecognized selector sent to instance - iphone

I am getting this error sort of randomly. It doesn't always happen but regardless, it doesn't make sense.
"[__NSCFNumber string]: unrecognized selector sent to instance"
shows up on this line:
_displayLabel.text = #"";
_displayLabel is an iVar of type UILabel and I am simply clearing the text from it here. Where is this NSCFNumber coming from? Is this an improper way of clearing the text from a UILabel?
Note: This is an ARC project.
UPDATE
I am getting a different error involving the same object in a different part of my code, again pretty randomly. Sometimes I see it, others I don't
-[NSConcreteMutableAttributedString string]: message sent to deallocated instance
I am seeing at this line
NSLog(#"displayLabel: %#", _displayLabel.text);
I'll reiterate that this is an ARC project and I have no release messages anywhere in my code. Could it be that ARC has inserted them poorly?

Related

Xcode 4.3.3 -[__NSArrayM length]: unrecognized selector sent to instance 0x6b6dc60

I have an iPhone application where i download information from the internet and put it into an NSString. It works fine, until i download large files and put it into that one string, then i get the error
-[__NSArrayM length]: unrecognized selector sent to instance 0x6b6dc60
At one point i was getting a EXC_BAD_ACCESS error, but now that's not showing up. I'm guessing that it is a memory problem but i dont know how to fix it. Is there a limit to how large a string variable can be? Any suggestions? I should also mention that the error sometimes doesn't show up, but most of the time it does. Thanks in advance.
Well, it looks like you're trying to get the length of the array by calling a method called length on an array, but to get the length of an array you use the count method like this for example:
NSInteger numberOfElements = [someArray count];
Hope this helps!
P.S. The length method exists but it is used on NSString objects to get the number of characters in the string.
----UPDATE-----
From Ray Wenderlich's "My App Crashed, Now What?" tutorial:
The error message “unrecognized selector sent to instance XXX” means that the app is trying to call a method that doesn’t exist.
So somewhere in your code, you are calling the length method on an object of type NSArray.
You are actually calling the length method on an object of type NSMutableArray, and you know that from the error because __NSArrayM represents an NSMutableArray object; a regular NSArray object would be represented as __NSArrayI (the suffixed "M" stands for "mutable" while the suffixed "I" stands for "immutable").
I even found a very similar question that has a very similar answer to mine:
NSArrayM length : unrecognized selector sent to instance
Heh, I had this before. Somewhere you're doing this: [array length]; but arrays use "count", not "length".
This is happening because you are trying to cast NSMutableArray to NSString, you can remove this error simply by using objectAtIndex:0.
when we use objectAtIndex:0 ,it returns object and in your case that object is your NSString & hence removes error.
e.g.
self.quizTextView.text=[questionTexts objectAtIndex:0];
Try turning on zombies to get a better error message. It's probably something being deallocated before you expect. You can also try running your app in the "Allocations" or "Leaks" instrument to track down why your objects are being released before you expect.

-[NSNull _isNaturallyRTL]: unrecognized selector sent to instance 0x20dfcd8

i know, this is strange but,
-[NSNull _isNaturallyRTL]: unrecognized selector sent to instance 0x20dfcd8
i found the problem, while using fb graphAPI.
It was in this line of code:
[tempValues setObject:textFieldBeingEdited forKey:tagAsNum];
I want to change it to
[tempValues setObject:textFieldBeingEdited.text forKey:tagAsNum];
but i dont find this anywhere in my code.
Do anybody hv idea, in which class it can be.
I would say that textFieldBeingEdited is either nil or NSNull. I'm not certain what tempValues is, so I don't know if its setObject:forKey: automatically converts nil to NSNull.

How to read 'unrecognized selector' error logs in obj-c / iphone apps

i've got the following crash log error in my app:
-[NSNull length]: unrecognized selector sent to instance 0x194adc8
How do i read this? Does it mean that:
I sent a 'length' message to a 'NSNull' object?
The 'length' method in the 'NSNull' class crashed when trying to call a selector on another class?
Also, if it is the former option, how can i get the stack trace to see which function caused this crash? That top line is the only error in my log.
Thanks
Door 1
NSNull does not respond to length
You can check the documentation for NSNull to see that this is the case.
Without having an idea of what your code base is doing I am not sure where to look, you must be calling [NSNull null]; at some point to get the NSNull object or you are using a framework somewhere that returns this.
It means you sent 'length' to NSNull and NSNull doesn't have a 'length' function.
Turning on NSZombies might help you (it keeps deallocated objects around so it can tell you which object you tried to access) but I think in this case you probably set an object to NSNull at some point (or it was returned from a function).
Anyway to turn on NSZombies, go to Project > Edit Active Executable > Arguments tab > Then add a variable called NSZombieEnabled and set the value to YES. Make sure you turn it off when you're done though because it can cause memory issues.
It means that you are using a Length method for calculating the string length
Like
If([strText Length]>0)
{
//do something here----
}
else
{
//Do somethig here--
}
So in above case- strText is NSNull then definitely a crash will accure and GDB will show a message like:
[NSNull length]: unrecognized selector sent to instance
As above told already Null don't have Length method.
For rescue:
check first:
if ((NSNull *)strText == [NSNull null])
{
return strText=#"";
}
This will prevent for crash for NSNULL
Zombies won't help in this case. As Paul.s said, NSNull is a valid object. You should get the stack trace when the app stops. Do you have the debugger pane open? Make sure it is. I'm pretty sure Xcode 4 always stops on exceptions with the stack trace. If for some reason you're still not seeing it, if you are at the (gdb) prompt, you can type 'bt' (backtrace) to get the trace.
Because you are coparing NSNull class to lenth
check before fo that
if ([NSString *str isKindOfClass:[NSNull null]]){
str=#"";
}
then check length for the str.
it works!thx

Pointer points to a different object: (Unrecognized selector sent to instance)

I got this weird crash in my app, when i try to call this function on my object pageModel
[pageModel pageTitle] isEqualToString:#"some text"];
This is the debugger dump
-[__NSArrayM isEqualToString:]: unrecognized selector sent to instance 0x661de40
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayM isEqualToString:]: unrecognized selector sent to instance 0x661de40'
and messing around with the debugger I found out some really strange behaviour
(gdb) po pageModel
<PXPage: 0x6622e20>
(gdb) po [pageModel pageTitle]
<__NSArrayM 0x661de40>(...
(gdb) po pageModel.pageTitle
<__NSArrayM 0x661de40>(...
It thinks it's a MutableArray but it's not. It should be a NSString...And some other time it was an UIImage and other time something else and so on.
Does anyone as a clue about what's going on here?
Thanks
This is a classic double release error. An object has been released too many times, the memory it occupies has been assigned to another object, so that other object is receiving messages meant for the old object.
You want set the NSZombieEnabled environment variable to YES in the scheme editor and run your application in the debugger. Google and/or stackoverflow search can help you find more information on this.
[pageModel pageTitle] is returns array. you are using NSString Class . it is the reason to crash. so check the data type of [pageModel pageTitle].

insertNewObjectForEntityForName: inManagedObjectContext: returning NSNumber bug?

I'm relatively well versed in CoreData and have been using it for several years with little or no difficulty. All of a sudden I'm now dumbfounded by an error. For the life of me, I can't figure out why
insertNewObjectForEntityForName:inManagedObjectContext:
is all of a sudden returning some sort of strange instance of NSNumber. GDB says the returned object is of the correct custom subclass of NSManagedObject, but when I go to print a description of the NSManagedObject itself, I get the following error:
*** -[NSCFNumber objectID]: unrecognized selector sent to instance 0x3f26f50
What's even stranger, is that I'm able to set some relationships and attributes using setValue:forKey: and all is good. But when I try to set once specific relationship, I get this error:
*** -[NSCFNumber entity]: unrecognized selector sent to instance 0x3f26f50
Has anyone ever encountered anything like this before? I've tried clean all targets, restarting everything, even changing the model to the relationship in question is a to-one instead of a to-many. Nothing makes any difference.
I've encountered the "unrecognized selector sent to instance 0x..." error before in a situation where the object I expect to be at the memory address "pointer" has been replaced by something else. Take this situation:
NSAutoReleasePool *pool = [[NSAutoReleasePool alloc] init];
NSString *someString = [NSString stringWithString:#"some string"]; // autoreleased object returned
[pool drain];
[pool release];
/*
some other code executes
*/
// since the string behind the someString variable has been autoreleased at this point, the memory that someString points to may be occupied by some other data type. the following may through an EXC_BAD_ACCESS error, or it may try and execute the selector on whatever is occupying that memory space
int stringLength = [someString length];
This example is painfully straightforward and my semantics may be a bit off here, but could it be possible that this is what is happening in your case in a more convoluted way? Maybe try:
[[NSEntityDescription insertNewObjectForEntityForName:#"entityName" inManagedObjectContext:managedObjectContext] retain]
and see what happens?