简体   繁体   English

由于未捕获的异常“ NSInvalidArgumentException”而终止应用程序,原因:“-[NSDecimalNumber长度]:

[英]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.

相关问题 由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“-[__NSCFBoolean length] - Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFBoolean length] 由于未捕获的异常'NSInvalidArgumentException'而终止应用程序,原因:'-[__ NSCFArray length]:无法识别的选择器已发送到实例 - Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFArray length]: unrecognized selector sent to instance 由于未捕获的异常'NSInvalidArgumentException'而终止应用程序,原因:'-[NSNull长度]:无法识别的选择器已发送到实例 - Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSNull length]: unrecognized selector sent to instance 由于未捕获的异常“ NSInvalidArgumentException”而终止应用程序,原因:“数据参数为nil” - Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'data parameter is nil' 由于未捕获的异常'NSInvalidArgumentException'而终止应用...原因(键:networkCarrier) - Terminating app due to uncaught exception 'NSInvalidArgumentException' …reason (key: networkCarrier) 由于未捕获的异常“ NSInvalidArgumentException”而终止应用程序,原因:“无法序列化CPDistributedMessagingCenter - Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Unable to serialize CPDistributedMessagingCenter 由于未捕获的异常“ NSInvalidArgumentException”而终止应用程序,原因:“-[SWRevealViewController manifestToggel:] - Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[SWRevealViewController revealToggel:] 由于未捕获的异常“ NSInvalidArgumentException”而终止应用程序,原因:“-[FBSDKProfilePictureView CGImage]: - Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[FBSDKProfilePictureView CGImage]: 由于未捕获的异常“ NSInvalidArgumentException”而终止应用程序,原因:“-[MKUserLocation标记]: - Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[MKUserLocation tag]: 由于未捕获的异常'NSInvalidArgumentException'而终止应用程序,原因:' - [UIButton setText:] - Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIButton setText:]
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM