开发者

NSArray componentsSeperatedByString Sigabrt

I get a Sigabrt at the NSlog and i have no idea why - any suggestions?

NSString* contentList = [NSString stringWithContentsOfFile:currentFilePath encoding:NSUTF8StringEncoding error:nil];
NSArray* contentArray = [contentList componentsSeparatedByString:@"$$"];

NSLog(@"%@%@",contentList,[contentArray count]);
kunden = [contentArray objectAtIndex:0];
kundenView.text = kunden;

Following Joes suggestions, I now got:

   NSString* contentList = [NSString stringWithContentsOfFile:currentFilePath encoding:NSUTF8开发者_开发问答StringEncoding error:nil];
NSArray* contentArray = [[contentList componentsSeparatedByString:@"$$"] retain];
if ([contentArray count] > 0) {
    NSLog(@"%@%@",contentList,[contentArray count]);
    kunden = [contentArray objectAtIndex:0];
    kundenView.text = kunden;
}

Which gives me an EXC_BAD_ACCESS at the NSLog thing.


I get a Sigabrt at the NSlog

Your NSLog statement is trying to print an integer as if it was an object:

NSLog(@"%@%@",contentList,[contentArray count]);
           ^
         Here!

Replace %@ with %d.

You can read more on format specifiers in the String Programming Guide.


You are not checking to make sure you have at least 1 element in your array. Accessing [contentArray objectAtIndex:0] will be an issue if the contentArray is empty.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜