错误:由于未捕获的异常'NSInvalidArgumentException'而终止应用程序,原因:' - [NSCFNumber isEqualToString:]:

时间:2011-09-05 12:10:29

标签: iphone objective-c

在我的应用程序中,我将Amount字段的值输入到textfield中,该字段的数据类型为float,然后将其插入到数据库中。当我运行我的应用程序时,它会出现以下错误。

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

这是我插入数据的代码:

 NSString *amt=txtTotalBill.text;
float amount = [amt floatValue];


NSString *insertData=[NSString stringWithFormat:@"insert into tbl_Bills(Amount) values ('%f')",amount];

此时app会出错:

  [label3 setText:[[BillTableArray objectAtIndex:indexPath.row]objectForKey:@"Amount"]];

2 个答案:

答案 0 :(得分:9)

[[BillTableArray objectAtIndex:indexPath.row]objectForKey:@"Amount"]返回的对象不是NSString

NSString *string = [NSString stringWithFormat:@"%@", [[BillTableArray objectAtIndex:indexPath.row]objectForKey:@"Amount"]];

[label3 setText:string];

答案 1 :(得分:1)

您正尝试将Number设置为标签的文字。标签文本must是字符串。因此,您需要先将Number值转换为NSString ...