' RLMException',原因:'无效的数据库' Objective-C的

时间:2016-04-12 04:21:01

标签: ios objective-c realm

我遇到了以下错误。我不知道为什么。我的XCode版本是7.2。请帮我解决这个问题。

这里只是复制defauly.realm。

NSFileManager *fileManager = [NSFileManager defaultManager];
NSError *error;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];

NSString *txtPath = [documentsDirectory stringByAppendingPathComponent:@"default.realm"];

if ([fileManager fileExistsAtPath:txtPath] == NO) {
    NSString *resourcePath = [[NSBundle mainBundle] pathForResource:@"default" ofType:@"realm"];
    [fileManager copyItemAtPath:resourcePath toPath:txtPath error:&error];
}

这是我收到的错误日志。

2016-04-12 10:47:04.791 APACRS[1190:84550] *** Terminating app due to uncaught exception 'RLMException', reason: 'Invalid database'
*** First throw call stack:
(
    0   CoreFoundation                      0x00000001089d0e65 __exceptionPreprocess + 165
    1   libobjc.A.dylib                     0x0000000108449deb objc_exception_throw + 48
    2   APACRS                              0x0000000105b1192d _Z18RLMSetErrorOrThrowP7NSErrorPU15__autoreleasingS0_ + 176
    3   APACRS                              0x0000000105b02f56 -[RLMRealm initWithPath:key:readOnly:inMemory:dynamic:error:] + 2409
    4   APACRS                              0x0000000105b037bc +[RLMRealm realmWithPath:key:readOnly:inMemory:dynamic:schema:error:] + 595
    5   APACRS                              0x0000000105b033c4 +[RLMRealm realmWithPath:readOnly:error:] + 51
    6   APACRS                              0x0000000105b03330 +[RLMRealm defaultRealm] + 69
    7   APACRS                              0x0000000105adb34d +[RLMObject allObjects] + 38
    8   APACRS                              0x0000000105a2593b +[WebImages getWebData] + 43
    9   APACRS                              0x0000000105a17d9b -[HomeViewController initController] + 171
    10  APACRS                              0x0000000105a17ba9 -[HomeViewController viewDidLoad] + 73
    11  UIKit                               0x0000000106ba5f98 -[UIViewController loadViewIfRequired] + 1198
    12  UIKit                               0x0000000106ba62e7 -[UIViewController view] + 27
    13  UIKit                               0x0000000106bf88b0 -[UINavigationController preferredContentSize] + 194
    14  UIKit                               0x0000000106b7d0aa -[UIPresentationController preferredContentSizeDidChangeForChildContentContainer:] + 59
    15  UIKit                               0x0000000106b79438 __56-[UIPresentationController runTransitionForCurrentState]_block_invoke + 95
    16  UIKit                               0x0000000106a1b4a2 _runAfterCACommitDeferredBlocks + 317
    17  UIKit                               0x0000000106a2ec01 _cleanUpAfterCAFlushAndRunDeferredBlocks + 95
    18  UIKit                               0x0000000106a3aaf3 _afterCACommitHandler + 90
    19  CoreFoundation                      0x00000001088fc367 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
    20  CoreFoundation                      0x00000001088fc2d7 __CFRunLoopDoObservers + 391
    21  CoreFoundation                      0x00000001088f1f2b __CFRunLoopRun + 1147
    22  CoreFoundation                      0x00000001088f1828 CFRunLoopRunSpecific + 488
    23  GraphicsServices                    0x000000010ad8ead2 GSEventRunModal + 161
    24  UIKit                               0x0000000106a0f610 UIApplicationMain + 171
    25  APACRS                              0x00000001059f591f main + 111
    26  libdyld.dylib                       0x00000001093af92d start + 1
)

0 个答案:

没有答案