2011-09-21 5 views
2

내 프로젝트를 완료했습니다. 그래서 시뮬레이터에서 테스트했는데 모든 것이 정상입니다. 하지만 불행히도이 프로젝트는 실제 아이폰에서 실행되지 않습니다. 이 오류가 발생합니다.'NSInvalidArgumentException'이라는 캐치되지 않은 예외로 인해 앱 종료.

"Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSFileManager copyItemAtPath:toPath:error:]: source path is nil'" 

이유가 무엇입니까?

RootViewController *rootViewController; 
... 
- (void) startApp; 
{ 
    [rootViewController init];   // error occured 
} 

RootViewController이 프로젝트 단순 파일 중 하나입니다 여기 내가 사용하는 몇 가지 코드입니다.

void Game::readData() 
{ 

    NSError *error; 
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); //1 
    NSString *documentsDirectory = [paths objectAtIndex:0]; //2 
    NSString *path = [documentsDirectory stringByAppendingPathComponent:@"GameInfo.plist"]; //3 

    NSFileManager *fileManager = [NSFileManager defaultManager]; 

    if (![fileManager fileExistsAtPath: path]) //4 
    { 
     NSString *bundle = [[NSBundle mainBundle] pathForResource:@"GameInfo" ofType:@"plist"]; 

     [fileManager copyItemAtPath:bundle toPath: path error:&error]; //6 
    } 

    NSMutableDictionary *savedStock = [[NSMutableDictionary alloc] initWithContentsOfFile: path]; 

    //load from savedStock example int value 
    gameMaxLevel = [[savedStock objectForKey:@"GameMaxLevel"] intValue]; 

    [savedStock release]; 

} 

무효 게임 ::되어, readData() {

NSError *error; 
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); //1 
NSString *documentsDirectory = [paths objectAtIndex:0]; //2 
NSString *path = [documentsDirectory stringByAppendingPathComponent:@"GameInfo.plist"]; //3 

NSFileManager *fileManager = [NSFileManager defaultManager]; 

if (![fileManager fileExistsAtPath: path]) //4 
{ 
    NSString *bundle = [[NSBundle mainBundle] pathForResource:@"GameInfo" ofType:@"plist"]; 

    [fileManager copyItemAtPath:bundle toPath: path error:&error]; //6 
} 

NSMutableDictionary *savedStock = [[NSMutableDictionary alloc] initWithContentsOfFile: path]; 

//load from savedStock example int value 
gameMaxLevel = [[savedStock objectForKey:@"GameMaxLevel"] intValue]; 

[savedStock release]; 

}

+0

은 (는) 더 많은 코드를 공유합니다. copyItemAtPath 메소드는 어디에 사용합니까? – Alin

+0

읽기/쓰기 plist 파일에서 copyitemAtPath 메서드를 사용했습니다. – bTagTiger

+1

GameInfo.plist의 이름이 똑같은지 확인하십시오. iOS는 대소 문자를 구분합니다. – Alin

답변

0

체크하여 GameInfo.plist 응용 프로그램의 리소스에 존재하고, 응용 프로그램 폴더 안에있는 경우 (있는 경우 두 개 이상의 장치에서 코드를 실행하고 있습니다. 문제가 해결되지 않으면 귀하의 완전한 예외 로그를 ​​공유하십시오.

관련 문제