Error:Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSCFNumber isEqualToString:]: - iphone

In my app i entered the value of Amount field into textfield and the datatype of that field is float and then insert it into database.when i run my app it gives following error.
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSCFNumber isEqualToString:]:
here is my code to insert data:
NSString *amt=txtTotalBill.text;
float amount = [amt floatValue];
NSString *insertData=[NSString stringWithFormat:#"insert into tbl_Bills(Amount) values ('%f')",amount];
and the app gives error at this point:
[label3 setText:[[BillTableArray objectAtIndex:indexPath.row]objectForKey:#"Amount"]];

The object returned by [[BillTableArray objectAtIndex:indexPath.row]objectForKey:#"Amount"] is not a NSString.
NSString *string = [NSString stringWithFormat:#"%#", [[BillTableArray objectAtIndex:indexPath.row]objectForKey:#"Amount"]];
[label3 setText:string];

you are trying to set Number as label's text. Where label text must be a string. So you need to first convert Number value into NSString...

Related

NSURL getFileSystemRepresentation:maxLength

Im having error with this code
NSString *theURL = #"http://www.w3schools.com/xml/cd_catalog.xml";
NSData *theData=[NSData dataWithContentsOfFile:[NSURL URLWithString:theURL]];
NSDictionary *theDic=[XMLReader dictionaryForXMLData:theData error:nil];
error is
2013-02-10 00:39:05.113 MyXml[4139:c07] -[NSURL getFileSystemRepresentation:maxLength:]: unrecognized selector sent to instance 0x7139670
2013-02-10 00:39:05.115 MyXml[4139:c07] *** Terminating app due to uncaught exception
'NSInvalidArgumentException', reason: '-[NSURL getFileSystemRepresentation:maxLength:]: unrecognized selector sent to instance 0x7139670'
*** First throw call stack:
(0x1c96012 0x10d3e7e 0x1d214bd 0x1c85bbc 0x1c8594e 0xad3ee4 0xad3e92 0xad3de2 0xaf2336 0x2bb8 0x15157 0x15747 0x1694b 0x27cb5 0x28beb 0x1a698 0x1bf1df9 0x1bf1ad0 0x1c0bbf5 0x1c0b962 0x1c3cbb6 0x1c3bf44 0x1c3be1b 0x1617a 0x17ffc 0x295d 0x2885)
libc++abi.dylib: terminate called throwing an exception
it is giving error because you are initing NSData with file by help of dataWithContentsOfFile, but actually you are giving URL to the NSData for initing it. because of this your code indirectly calling method of file getFileSystemRepresentation:maxLength: on NSURL ,thats why it is giving error-Unknown selector.
use this dataWithContentsOfURL instead of dataWithContentsOfFile
NSString *theURL = #"http://www.w3schools.com/xml/cd_catalog.xml";
NSData *theData=[NSData dataWithContentsOfURL:[NSURL URLWithString:theURL]];

error with label.text and NSNumber

I would like to do this:
I have a dictionary like this:
[myMutableDictionary setValue:myNSNumber forKey:#"myKey"];
myNSNumber is an NSNumber.
myCell.label.text = [self.myMutableDictionary objectForkey#"myKey"];
I have an error when I assign the number stored in my dictionary to my label in myCell.
The error is:
je suis la 2011-05-02 15:01:01.264 []
-[NSCFNumber isEqualToString:]: unrecognized selector sent to instance
0x225d00 2011-05-02 15:01:01.319 []
*** Terminating app due to uncaught exception
'NSInvalidArgumentException', reason:
'-[NSCFNumber isEqualToString:]:
unrecognized selector sent to instance
0x225d00'
NSNumber is not an NSString and the text of the label needs to set to an NSString.
NSNumber *num = (NSNumber*)[self.myMutableDictionnary objectForkey#"myKey"];
myCell.label.text = [num stringValue];
Here you can do it by 2 ways
first is myCell.label.text = [[self.myMutableDictionnary objectForkey#"myKey"] stringValue];
second is myCell.label.text = [NSString stringWithFormat:#"%d",[self.myMutableDictionnary objectForkey#"myKey"]] ;

confused as how to use componentsSeparatedByString on iphone

after nsXml pasring value of my NSMutable array AB
=\n\n\n\thttp://xyz.com/uploads/resto_6298__20091209#1621_250.JPG\n\thttp://xyz.com/uploads/resto_6298__200912099_2_250.JPG\n"
now i am doing this to make this url working
NSString *sw=AB;
NSArray *strings = [sw componentsSeparatedByString: #"\n\t"];
NSLog(#"what I have %#",strings);
but my app always crash and i am getting this error
[NSCFArray componentsSeparatedByString:]: unrecognized selector sent to instance 0x1b28b0
2010-10-05 10:17:31.382 Wat2Eat[2311:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSCFArray componentsSeparatedByString:]: unrecognized selector sent to instance 0x1b28b0'
how to parse this AB so that i can extract exact URL
NSString *sw=AB;
AB is an NSMutableArray?
the compiler should print a warning if you try to do this. You tried to assign an NSArray to an NSString. This will not work.
Did you mean NSString *sw = [AB objectAtIndex:foo]; ?

NSCFArray length]: error, array regex

StringReply = [[NSString alloc] initWithData:dataReply encoding:NSUTF8StringEncoding];
//Regex Out Artist Name
//NSString *regEx = ;
NSArray *iTunesAristName = [stringReply componentsMatchedByRegex: #"(?<=artistname\":\")([^<]+)(?=\")"];
if ([iTunesAristName isEqual:#""]) {
NSLog(#"Something has messed up");
//Regex Out Song Name
}else{
NSLog(iTunesAristName);
}
NSLog(iTunesAristName);
[stringReply release];
I just keep getting this error ?
2010-09-29 21:15:16.406 [2073:207] *** -[NSCFArray length]: unrecognized selector sent to instance 0x4b0b800
2010-09-29 21:15:16.406 [2073:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSCFArray length]: unrecognized selector sent to instance 0x4b0b800'
2010-09-29 21:15:16.407 [2073:207] Stack: (
please help its driving me crazy
The first argument to NSLog is supposed to be a format string. You're passing an NSArray. When the function tries to treat your array as a string, you get that error. Instead, use NSLog(#"%#", iTunesAristName);.
Chuck has answered your question, but I've noticed something else that is problematic.
NSArray is an array, not a string, so [iTunesArtistName isEqual:#""] will never return true, because they are different classes. Even if iTunesArtistName was a string, it should be compared using the isEqualToString: method, not isEqual:.
If you want to extract only the artist's name, you might be able to do this:
NSArray *matches = [stringReply componentsMatchedByRegex: #"(?<=artistname\":\")([^<]+)(?=\")"];
if ([matches count] == 0)
{
NSLog(#"Could not extract the artist name");
}
else
{
NSString *iTunesArtistName = [matches objectAtIndex:0];
NSLog(#"Artist name: %#", iTunesArtistName);
}
I see you're using RegexKitLite, make sure you import libicucore.dylib, i was getting the same error until i imported that library.

NSDictionary objectForKey throws Exception

I've built an XML parser in Objective-C and the message objectForKey throws an NSException but I don't know why.
aPicture = [[Picture alloc] init];
aPicture.pictureID = [[attributeDict objectForKey:#"id"] integerValue];
Here is the message of the exception that i don't understand:
2010-08-09 21:27:32.223 rh[6375:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Picture setPictureID:]: unrecognized selector sent to instance 0x592e0b0'
After a long search i got my mistake...
I have forgotton to synthezise the pictureID selector.
....