私はiOSアプリケーションの開発にかなり新しいです。エラーはソースパスがnilであると言います
私はDBにレコードを保存し、そこから取り出したサンプルDBアプリを構築しようとしています。
私はシミュレーターでテストする際にアプリケーションがうまく動作します。私はローカルデータベースを作成し、必要に応じてプログラムのコピーを作成しています。また、ローカルDBが 'バンドルリソースのコピー'で参照されていることを確認しました。
しかし、私は取得していますエラーは "*がキャッチされない例外により 'NSInvalidArgumentException'、理由にアプリを終了: '* - [NSFileManager copyItemAtPath:toPath:エラー:]:ソースパスがnilである'"、です。
それはシミュレータのための完璧な仕事が、私は私のデバイスでテストしない場合は、「[ゼロ:databasePathFromApp toPath:DBPATHエラーFileManagerのcopyItemAtPath]」
私はこの問題の原因となるコードの一部が だと思います。
助けを期待。私のコードである
、
- (id)init {
self = [super init];
//Datbase Name
[email protected]"Person.sqlite3";
//Getting DB Path
NSArray *documentsPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDir = [documentsPath objectAtIndex:0];
DBPath=[documentsDir stringByAppendingPathComponent:DBName ];
//DBPath = [[NSString alloc] initWithString: [documentsDir stringByAppendingPathComponent:DBName]];
NSLog(@"DBPath is %@",DBPath);
return self;
}
-(void)checkAndCreateDB{
BOOL Success;
//NSFileManager maintains File
NSFileManager *FileManager = [NSFileManager defaultManager];
NSLog(@"line 1");
//Checks Database Path
Success = [FileManager fileExistsAtPath:DBPath];
NSLog(@"line 2");
//If file exists, it returns true
if(Success)return;
NSLog(@"line 3");
//NSString *databasePathFromApp = [[[NSBundle mainBundle]resourcePath]stringByAppendingPathComponent:DBName];
// Get the path to the database in the application package
NSString *databasePathFromApp=[[NSBundle mainBundle] pathForResource:@"Person.sqlite3" ofType:@"sqlite3"];
NSLog(@"line 4");
[FileManager copyItemAtPath:databasePathFromApp toPath:DBPath error:nil];
//[FileManager release];
NSLog(@"line 5");
}
自分のアプリケーションがクラッシュしながらラインのNSLog(4行目)後のデバイスでテスト。しかし、シミュレータでうまくいく。 プラカシュ
を離れて取得しますが、iOSデバイスでは、大文字と小文字が区別されますクイック返信ありがとう:)私の既存のコードはまったく同じであり、私のローカルデータベースもドキュメントにあります。 NSArray *ドキュメントパス= NSSearchPathForDirectoriesInDomains(NSDocumentDirectory、NSUserDomainMask、YES); NSString * documentsDir = [ドキュメントパスobjectAtIndex:0]; DBPath = [documentsDir stringByAppendingPathComponent:DBName]; まだデバイスでは機能しません。 – suj