This question already has answers here:
How can I debug 'unrecognized selector sent to instance' error
(9 answers)
Closed 7 years ago.
I have a callback method when a socket receives data like this...
+ (void) dataReceived:(NSData *)data {
NSData *dataCopy = [data copy];
NSString *msg = [[NSString alloc] initWithData:dataCopy encoding:NSUTF8StringEncoding];
NSLog(#"msg: %#", msg);
}
I can see in the debugger that both data and dataCopy contain the correct string data. The dataCopy is made without an issue but when the msg line is called, I blow up w/ this.
2015-04-02 15:45:10.179 Sandbox[15218:539849] -[__NSCFString bytes]:
unrecognized selector sent to instance 0x7f9c71447870 2015-04-02
15:45:10.184 Sandbox[15218:539849] *** Terminating app due to uncaught
exception 'NSInvalidArgumentException', reason: '-[__NSCFString
bytes]: unrecognized selector sent to instance 0x7f9c71447870'
I don't understand, I can see the data is correct, I thought making the copy is what prevents access to overwritten memory. Any idea what is going on here?
Seems that your "delegate" method gets called with a NSString instead of a NSData. Copying the received object won't help you in this case, as you're just copying a string into another string. You'll need to dig deeper and see why dataReceived: doesn't receive the expected NSData object.
Related
I am getting the following exception, which is terminating the app.
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayM objectForKey:]: unrecognized selector sent to instance 0x7abe4f90'
Following is the code:
- (NSMutableData*)dataForConnection:(URLConnection*)connection {
NSMutableData *data = [receivedData objectForKey:connection.tagKey]; // Exception Here
return data;
}
Could anyone please suggest how to fix it? Thank you in advance!
Problem is due to not allocating receivedData properly, since you have declared it as instance variable, so you should make it using the property declaration like this:
#property(nonatomic, strong) NSMutableDictionary *receivedData;
This will ensure that receivedData does not get released and reference this using self.receivedData in your code.
Maybe this is helpful
[__NSArrayM objectForKey:]
NSArray have not method called objectForKey:
Your object receivedData is NSArray class , change to NSDictionary.
I am getting an exception from my published application which is:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFType encodeWithCoder:]: unrecognized selector sent to instance 0x19a8a170'
and happens because of:
#property(nonatomic,retain)NSMutableDictionary *settings;
settingsData = [NSKeyedArchiver archivedDataWithRootObject:self.settings];
As this is a remote report, I cannot debug or find out the problematic object that was added to NSMutableDictionary without conforming to NSCoding protocol. Because of this reason, I am trying to find that object when an exception occurs. Remove it from the array and log it to learn what it is.
So, I use the following block:
NSData* settingsData = nil;
#try {
settingsData = [NSKeyedArchiver archivedDataWithRootObject:self.settings];
}
#catch (NSException *exception) {
for (id key in self.settings) {
id value = [self.settings objectForKey:key];
if(![value respondsToSelector:#selector(encodeWithCoder:)]){}
}
}
#finally {
}
However, this exception is never catched on device and simulator. (tested on iOS7 and iOS8).
I don't want to test parameters if there are no exceptions every single time...
I don't want to test values while setting them to dictionary. (As already added ones will also create problem too)
Is there a way to catch this kind of exception?
I am using BlackRaccoon to download a file from FTP server. Following is the code:
- (IBAction)download:(id)sender {
downloadData = [NSMutableData dataWithCapacity: 1];
downloadFile = [[BRRequestDownload alloc] initWithDelegate: self];
downloadFile.path = #"psnewsletter.pdf";
downloadFile.hostname = #"server";
downloadFile.username = #"user";
downloadFile.password = #"pswd";
[downloadFile start];
}
Its gives following error
2014-02-20 11:48:43.526 BlackHillPrimarySchool[2036:a0b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[MainViewController requestFailed:]: unrecognized selector sent to instance 0xcd609f0'
Any help will be appreciated.
requestFailed: is one of the BRRequest delegate method that you must implement in your view controller.
- (void)requestFailed:(BRRequest *)request {
BRRequestError *reqError = request.error;
// check the error, handle as needed.
}
I'm not sure how your code even compiled. This is a required method of the protocol.
core data getting on my nerves. i' m deleting old data and want to insert new data received from server.
now the deleting part gives a "sigabort":
-[NSManagedObjectContext delete:]: unrecognized selector sent to instance 0x522f550
2013-09-27 14:05:56.592 * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSManagedObjectContext delete:]: unrecognized selector sent to instance 0x522f550'
* First throw call stack:
(0x320f82a3 0x39d4797f 0x320fbe07 0x320fa531 0x32051f68 0x1b6c53 0x1868e5 0x3a15f11f 0x3a16d259 0x3a16d3b9 0x3a193a11 0x3a1938a4)
libc++abi.dylib: terminate called throwing an exception
deleting happens in background and nsmanagedobjectcontext is a privet concurrency type
i printed the pointer for context and object context
po context NSManagedObjectContext: 0x522f550
and
po tmpCon.managedObjectContext NSManagedObjectContext: 0x522f550>
and the code for deleting is:
NSError *errorAllCons = nil;
NSFetchRequest *allevents = [[NSFetchRequest alloc] init];
[allevents setEntity:[NSEntityDescription entityForName:#"TEventContact" inManagedObjectContext:context]];
NSArray *allCons = [context executeFetchRequest:allevents error:&errorAllCons];
for (TEventContact *tmpCon in allCons)
{
[context delete:tmpCon];
}
and it crashes on [context delete:tmpCon];
can someone let me know what am i doing wrong?
Use
[context deleteObject:tmpCon];
It will solve the problem
do it like this for deleting an object permanently
for (TEventContact *tmpCon in allCons)
{
[context deleteObject:tmpCon] /// for deleting object in context
}
[context save]; /// to reflect changes in database you need to save that context
without saving the context it doesn't reflect on data base and that may cause DIRTY_READ for another context
i've a piece of code that should get the current location and than put lat and long in a string.
when a new location is found i put it in a NSString
currentLatit = [NSString stringWithFormat:#"%f",newLocation.coordinate.latitude];
currentLongit = [NSString stringWithFormat:#"%f",newLocation.coordinate.longitude];
Than when i press a button i do:
NSLog(currentLatit);
[[UIApplication sharedApplication] openURL:[[NSURL alloc] initWithString: [NSString stringWithFormat:#"http://maps.google.com/maps?saddr=%#,%#&daddr=%#,%#",currentLatit,currentLongit,detailLatitudine,detailLongitudine]]];
but when i execute this, i get this error:
-[__NSCFArray length]: unrecognized selector sent to instance 0x1e1830
2011-11-15 11:29:07.567 Marcovaldo[771:707] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFArray length]: unrecognized selector sent to instance 0x1e1830'
*** First throw call stack:
(0x30ae78bf 0x37c8c1e5 0x30aeaacb 0x30ae9945 0x30a44680 0x30a310a9 0x30ac5a97 0x30a42217 0x30a55b8f 0x37b09b9b 0x37b09b3b 0x7253 0x30a41435 0x32a9c9eb 0x32a9c9a7 0x32a9c985 0x32a9c6f5 0x32a9c321 0x32a8f99b 0x30abbb4b 0x30ab9d87 0x30aba0e1 0x30a3d4dd 0x30a3d3a5 0x3366bfed 0x32aaf743 0x2221 0x21e0)
terminate called throwing an exception(gdb)
The error occur on the NSLog execution
realy cannot understand what's wrong whit this simple code...
thanks for any help
-UPDATE-
changed the NSLog as follow:
NSLog(#"%#",currentLatit);
Now the app crash with BAD_ACCESS_EXCEPTION on the NSLog
No, it seems the app crashed at some point other than NSLog. Please clean and build. Or Enable NSZombie and get the exact error location.
Update:
Just do like as following and try.
if( currentLatit )
[currentLatit release];
if( currentLongit )
[currentLongit release];
currentLatit = [[NSString stringWithFormat:#"%f",newLocation.coordinate.latitude] retain];
currentLongit = [[NSString stringWithFormat:#"%f",newLocation.coordinate.longitude] retain];