我遇到一个错误,在IOS中说nil参数

时间:2012-08-31 06:10:57

标签: ios

在IOS中,我希望使用ViewController的功能,在运行之后一直说错误:nil argument.I不知道如何解决它,如果有人知道可以帮帮我?

此' java代码:

#import "MasterViewController.h"  
#import <GHUnitIOS/GHUnit.h>  

@class MasterViewController;  

@interface MasterViewControllerTest : GHViewTestCase{  
NSString* _type;  
NSString* _msgId;  
NSString* _url;  
NSString* _opened;  
}@property(nonatomic,retain) MasterViewController* masterViewController;  
@end  

@implementation MasterViewControllerTest  
@synthesize masterViewController;  

-(void)setUp{  
MasterViewController *viewController = [[MasterViewController alloc]init];  
self.masterViewController = viewController;  
}  

-(void)testPostViewTimeToServ{      
_type = @"m";  
_url = nil;  
_opened = nil;  
_msgId = @"";  

bool resultValue = [self.masterViewController saveAndPostViewMagBodyTime:_type      arg_url:_url arg_open:_opened mid:_msgId];  

GHAssertNotEquals(resultValue, YES, @" post msgIs is nil fail");  

}  
@end  

并且testPostViewTimeToServ错误显示为:


测试套件&#39;测试&#39;开始。 启动MasterViewControllerTest / testPostViewTimeToServ 2012-04-02 20:50:42.269 kMsgGHUnitTests [7747:10b0f] 名称:NSInvalidArgumentException 档案:未知 行:未知 原因: * - [NSPlaceholderString initWithString:]:nil参数


为什么?

1 个答案:

答案 0 :(得分:1)

您收到错误是因为您在调用nil时为两个参数传递了saveAndPostViewMagBodyTime:arg_url:arg_open:arg_mid:值。在该方法的某处,您使用其中一个或两个nil值来初始化一个字符串对象,这就是抛出错误。

避免错误的简单方法是传递空字符串值而不是nil。

_url = @"";  
_opened = @"";