Exception throwing JSON supporting program in iphone - iphone

I downloaded JSON files. I added these files in project directory. But when I am runnig program I am getting an error which is...
-[__NSCFDictionary
JSONRepresentation]: unrecognized
selector sent to instance 0x6003d50
* Terminating app due to uncaught exception
'NSInvalidArgumentException', reason:
'-[__NSCFDictionary
JSONRepresentation]: unrecognized
selector sent to instance 0x6003d50'
* Call stack at first throw:
I imported header file #import "JSON/JSON.h" and I wrote jsocn code in viewDidLoad function which is like below...
NSDictionary *requestData = [NSDictionary dictionaryWithObjectsAndKeys:
#"grio", #"username",
#"hellogrio", #"password",
nil];
NSString* jsonString = [requestData JSONRepresentation];
NSLog(#"%#", jsonString);
Kindly help me.
Thanks in advance.

I am guessing you are using json-framework. You probably forgot to add -all_load to the linker flags. See this question for more details.

It's not clear from your question which JSON implementation you're using, but the error means that you're sending the JSONRepresentation message to an NSDictionary. The dictionary does not understand the message and raises an exception.
It seems that either you're not using the JSON library correctly or that you have not installed it correctly in your project.

Related

Why am I getting an "unrecognised selector sent to instance" error when I have defined the method?

I'm building an iOS (5.1) app on Xcode (4.4.1), and I'm almost done with the first phase of development, but I'm stuck on the final line of code. I've been using Kumulos as a backend & API solution, and at the moment all the API is working fine except for this bit:
Kumulos* k = [[Kumulos alloc]init];
[k setDelegate:self];
[k createNewTimePointWithJourneyIDFK:[journeyID integerValue]
andTime:currentDate andLat:[lat floatValue] andLon:[lon floatValue]];
When it hits the createNewTimePointWithJourneyIDFK: method, it terminates. In the log it mentions this method and says an unrecognised selector was sent to an instance.
Now I realise this question has been asked a million times on SO, but I've 1) checked that the method has been defined, and 2) that it has been called correctly (or at least to the best of my knowledge). The way I've done the above is the way I've done the rest of the API calls, and they work well, so I can't see what the problem is. Very frustrating, I've spent hours on this last line! So please don't think I've come hear after a few minutes of not knowing what to do.
The error message
2012-08-11 22:36:58.769 busApp4Kumulos[5485:707] -[Kumulos
createNewTimePointWithJourneyIDFK:andTime:andLat:andLon:]:
unrecognizedselector sent to instance 0x3d1b70 2012-08-11 22:36:58.778
busApp4Kumulos[5485:707]
*** Terminating app due to uncaught exception
'NSInvalidArgumentException', reason: '-[Kumulos
createNewTimePointWithJourneyIDFK:andTime:andLat:andLon:]:
unrecognized selector sent to instance 0x3d1b70'
*** First throw call stack:
(0x35add88f 0x37e84259 0x35ae0a9b 0x35adf915 0x35a3a650 0x3ef5
0x37f86de3 0x37f86785 0x37f80e3f 0x35ab1b01 0x35ab112f 0x35ab0351
0x35a334a5 0x35a3336d 0x376cf439 0x3353fcd5 0x2dd9 0x2d74)
terminate called throwing an exception(lldb)
The Method
This is located in the Kumulos.m file.
-(KSAPIOperation*) createNewTimePointWithJourneyIDFK:(NSInteger)journeyIDFK
andTime:(NSDate*)time andLat:(float)lat andLon:(float)lon{
NSMutableDictionary* theParams = [[NSMutableDictionary alloc]init];
[theParams setValue:[NSNumber numberWithInt:journeyIDFK] forKey:#"journeyIDFK"];
[theParams setValue:time forKey:#"time"];
[theParams setValue:[NSNumber numberWithFloat:lat] forKey:#"lat"];
[theParams setValue:[NSNumber numberWithFloat:lon] forKey:#"lon"];
KSAPIOperation* newOp = [[KSAPIOperation alloc]initWithAPIKey:theAPIKey
andSecretKey:theSecretKey andMethodName:#"createNewTimePoint"
andParams:theParams];
[newOp setDelegate:self];
[newOp setUseSSL:useSSL];
//we pass the method signature for the kumulosProxy callback on this thread
[newOp setCallbackSelector:#selector( kumulosAPI: apiOperation: createNewTimePointDidCompleteWithResult:)];
[newOp setSuccessCallbackMethodSignature:[self methodSignatureForSelector:#selector(apiOperation: didCompleteWithResult:)]];
[newOp setErrorCallbackMethodSignature:[self methodSignatureForSelector:#selector(apiOperation: didFailWithError:)]];
[opQueue addOperation:newOp];
return newOp;
}
The only thing I can think of is that something got stale in your project. Have you tried cleaning (via Product → Clean) and rebuilding?

NSURL Exceptions

I am trying to grab a path value from an array for an NSURL to set an icon in my app. I get an
NSInvalidArgumentException', reason: '-[__NSArrayI length]: unrecognized selector sent to instance 0x5622590.
If I use an nslog I get the expected output:
NSLog(#"%#",[[wforecast.wicons objectAtIndex:0]valueForKey:#"nodeContent"]);
Which gives me:
Im setting the value as follows
NSURL *urlpath;
NSString *urls = [[wforecast.wicons objectAtIndex:0] valueForKey:#"nodeContent"];
urlpath = [NSURL URLWithString:(NSString *)urls];
I appreciate this is a longwinded way of doing things but I was trying to break up the individual components to find out what was going wrong but I am at a loss!
You have essentially the same problem as this other questioner had. You passed an object that is not an NSString where you needed to pass an NSString.
Use the debugger to determine exactly where the exception occurred. If you haven't done this, I wouldn't be so sure that the code you showed is what caused it; the debugger will tell you where the exception occurred with no room for doubt.
Once you've found where the exception occurred, you can examine the object that you passed, and look back at where you got it from. You need to fix either how you retrieve the string or how you stored it in the place you're now getting it from.

Unrecognized selector to an openfeint unlock achievement call

I use the call as it is supposed to be used, but it causes a crash.
//someId is a correct achievement ID
[OFAchievementService unlockAchievement:#"someId"];
and I get the following error
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+[OFAchievementService unlockAchievement:]: unrecognized selector sent to class 0x26f1c8'
I also get a warning
warning: 'OFAchievementService' may not respond to '+unlockAchievement:'
How is one supposed to call this function? This looks correct according to examples.
Try:
OFAchievementService *openfeint = [[OFAchievementService alloc] init];
[openfeint unlockAchievement:#"someId"];
[openfeint release];
instance methods begin with - class level methods begin with +.
With OpenFeint SDK 2.7+ try:
/* The following example shows how to unlock an achievement completely in one step without bothering to show a notification: */
[[OFAchievement achievement: achievementId] updateProgressionComplete: 100.0f andShowNotification: NO];
The following line just worked well enough for me (in OpenFeint SDK version 2.10i):
[[OFAchievement achievement:#"achievementID"] unlock];

RegexKitLite & Unrecognized Selector Sent to Instance Error

I am not sure why the following line:
addDetails.Address = [addDetails.Address stringByReplacingOccurrencesOfRegex:#" +" withString:#" "];
causes an "Unrecognized Selector Sent to Instance" error, closing my iPhone App in my Simulator(XCode).
What's wrong with my code?
stringByReplacingOccurrencesOfRegex:withString: is a NSString category defined in RegexKitLite.h of RegexKitLite lib.
Looks like you haven't add this category into your project properly see:
http://regexkit.sourceforge.net/RegexKitLite/#AddingRegexKitLitetoyourProject
or addDetails.Address is not NSString.

trying to obtain an objects title variable gives unrecognized selector sent to instance

I have an object which holds a title and an indexReference. I save the object to an array and that works correctly.
I then try to load from the array and populate the tableview.
I use this code.
//fill it with contents
SavedFav *temp = [tableViewData objectAtIndex:indexPath.row];
cell.textLabel.text = temp.title;
I then get an error as the following
2010-07-01 15:42:46.386 Daily Quote[1308:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSCFString title]: unrecognized selector sent to instance 0x23f6688'
What is causing this problem?
Thanks in advance.
"temp" is a string obviously, so it's too many answers to give, either you filled tableViewData with strings and trying to obtain title from a string (which is unrecognized) or you have problem with memory there, without seeing more code it's hard to say.
however try
cell.textLabel.text = temp;
and check what's inside, that will give you a good lead.