[英]Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSDecimalNumber length]:
With these lines of code: 使用以下代码行:
PayPalPayment *payment = [[PayPalPayment alloc] init];
NSLog(@"Price %@",[self.product objectForKey:@"Price"]);
NSString *string = [self.product objectForKey:@"Price"];
payment.amount = [[NSDecimalNumber alloc] initWithString:string];
my app is crashing with this log: 我的应用程序崩溃与此日志:
[NSDecimalNumber length]: unrecognized selector sent to instance
The NSLog is returning: NSLog返回:
Price 96.67
Whay is it crashing??? Whay崩溃了吗???
I would guess that you have a type problem, most likely with the object at 我猜你有一个类型问题,最有可能与对象有关
[self.product objectForKey:@"Price"];
My guess is that this object is already an NSDecimalNumber
, and when you treat it as a string and then call the initWithString method using it, bad things happen 我的猜测是该对象已经是
NSDecimalNumber
,并且当您将其视为字符串然后使用它调用initWithString方法时,会发生不好的事情
put a breakpoint at: 在以下位置设置断点:
payment.amount = [[NSDecimalNumber alloc] initWithString:string];
and then type po [string class]
into the debugger. 然后在调试器中键入
po [string class]
。
This will show you the type of object stored at [self.product objectForKey:@"Price"];
这将显示存储在
[self.product objectForKey:@"Price"];
的对象的类型[self.product objectForKey:@"Price"];
It looks like your string
object isn't an NSString
. 看起来您的
string
对象不是NSString
。 Looks like it's actually an NSDecimalNumber
- set a breakpoint there and inspect the object. 看起来实际上是一个
NSDecimalNumber
在此处设置一个断点并检查对象。 What kind of object is self.product
? self.product
是什么样的对象?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.