Winnie
Winnie

Reputation: 769

I meet an error says nil argument in IOS

In IOS,I want to UT the ViewController's function,after running it keeps saying error:nil argument.I don't know how to solve it, if anybody know that can help me?

this' the java code:

#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  

and the testPostViewTimeToServ error show is:


Test Suite 'Tests' started. Starting MasterViewControllerTest/testPostViewTimeToServ 2012-04-02 20:50:42.269 kMsgGHUnitTests[7747:10b0f] Name: NSInvalidArgumentException File: Unknown Line: Unknown Reason: * -[NSPlaceholderString initWithString:]: nil argument


why?

Upvotes: 1

Views: 2976

Answers (1)

jonkroll
jonkroll

Reputation: 15722

You are getting the error because you passing nil values for two arguments in your call to saveAndPostViewMagBodyTime:arg_url:arg_open:arg_mid:. Somewhere in that method you are using one or both of those nil values to initialize a string object, and that is throwing the error.

The easy way to avoid the error is to pass an empty string value instead of nil.

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

Upvotes: 1

Related Questions