简体   繁体   中英

xCode 4.2 error

I'm getting this error when I try to load another view:

2012-02-21 20:31:38.477 App Demo[1671:f803] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSPlaceholderString initWithString:]: nil argument'

I couldn't find where is the error exactly.

Any help?

update

NSString *pn1 = player1name.text;
NSString *pn2 = player2name.text;
NSString *pn3 = player3name.text;
NSString *pn4 = player4name.text;
NSString *k = kingdomLevel.text;

Kscores *kscores = [[Kscores alloc] initWithNibName:nil bundle:nil];
kscores.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:kscores animated:YES];


[[kscores player1name] setText:[NSString stringWithString:(NSString *)pn1]];
[[kscores player2name] setText:[NSString stringWithString:(NSString *)pn2]];
[[kscores player3name] setText:[NSString stringWithString:(NSString *)pn3]];
[[kscores player4name] setText:[NSString stringWithString:(NSString *)pn4]];
[[kscores king] setText:[NSString stringWithString:(NSString *)k]];

breakpoint stopped at this code

[[kscores player1name] setText:[NSString stringWithString:(NSString *)pn1]];

What's the point of doing stringWithString: ? You can just set it directly like [[kscores player1name] setText:pn1];

You're getting the error because pn1 is nil, and you can't pass nil to stringWithString: .

That means that pn1 is nil in the line:

[[kscores player1name] setText:[NSString stringWithString:(NSString *)pn1]];

That means that player1name or player1name.text are nil in the line:

NSString *pn1 = player1name.text;

You are trying to pass a nil argument: [[kscores player1name] setText:nil]; since [NSString stringWithString:(NSString *)pn1] is NULL .

Instead, try this: [[kscores player1name] setText: pn1]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM