2014-03-12 138 views
0

此代碼導致崩潰,錯誤終止應用程序由於未捕獲的異常'NSInvalidArgumentException',原因:'executeFetchRequest:錯誤:提取請求必須具有實體。NSInvalidArgumentException',原因:'executeFetchRequest:錯誤:

self.devices = [[managedObjectContext executeFetchRequest:fetchRequest error:nil] mutableCopy]; 
NSLog(@"point one"); 
NSString *[email protected]"trip1"; 
NSFetchRequest *request = [[NSFetchRequest alloc] init]; 

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"thetrip== %@", yourTrip]; 

[request setEntity:[NSEntityDescription entityForName:@"thetrip" inManagedObjectContext:managedObjectContext]]; 

[request setPredicate:predicate]; 

NSError *error = nil; 

NSArray *array = [managedObjectContext executeFetchRequest:request error:&error]; 
if (array == nil) 
{ 
    NSLog(@"problemo"); 
} 

崩潰發生在NSError * error = nil後;

+1

而且,你有一個名爲'thetrip'的實體嗎?記錄實體描述。 – Wain

回答

0

我纔能有什麼錯誤是信息更改

NSLog(@"problemo"); 

NSLog(@"problemo %@", [error localizedDescription]); 

。我認爲(以及@Wain)你可能沒有一個名爲'thetrip'的實體(也許theTrip?知道Core Data區分大小寫)。具有本地化描述的日誌會給你一些關於你的問題的提示。

+0

屬性名稱是thetrip,我記錄了本地化的描述,它的值爲yourtrip(trip1),但我永遠不會到NSLog(@「problemo%@」,[errors localizedDescription]);它在此之前墜毀。 – user1828081

+0

如果在模擬器中發生這種情況,請嘗試從模擬器設備中刪除應用程序,執行項目清理並再次嘗試您的應用程序。 – javierfdezg

+0

嘗試了多次,它崩潰的方式完全相同的錯誤***由於未捕獲的異常「NSInvalidArgumentException」終止應用程序,原因:'executeFetchRequest:錯誤:一個獲取請求必須有一個實體。' – user1828081

相關問題