应用程序在某行崩溃,为啥?

Posted

技术标签:

【中文标题】应用程序在某行崩溃,为啥?【英文标题】:App is crashing in a certain line, Why?应用程序在某行崩溃,为什么? 【发布时间】:2011-11-09 08:43:31 【问题描述】:

我的真实代码充满了 NSLog 的, 以下行是他崩溃的原因,但我不明白为什么

NSString *newDir = [文档目录 stringByAppendingPathComponent:file];

这是整个方法:

 - (void)viewDidLoad   

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);   
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSFileManager *fileManager = [NSFileManager defaultManager];    
    NSArray* newArray= [[NSArray alloc]init];   
    newArray=  [fileManager contentsOfDirectoryAtURL:[NSURL fileURLWithPath:@"/Users/admin/Library/FotoAppFotos/"]
    includingPropertiesForKeys:[NSArray arrayWithObject:NSURLNameKey]                                        options:NSDirectoryEnumerationSkipsHiddenFiles error:nil];         
    categories= [NSMutableArray arrayWithArray: newArray];

        for(NSString *file in categories)   

        NSString *newDir = [documentsDirectory stringByAppendingPathComponent:file]; // in this line the app crashes        
        [categories addObject:newDir]; //categories         
         
        [super viewDidLoad]; 
    

如前所述,文档目录和文件的 NSLog 打印是:

documentsDirectory:/Users/admin/Library/Application Support/iPhone 模拟器/4.3/Applications/D5AB6F90-0420-4A66-B141-D27AB2C11C3C/Documents

file://localhost/Users/admin/Library/FotoAppFotos/Audio/

整个崩溃日志是:

2011-11-09 09:21:42.989 TestTest[543:207] -[NSURL length]: unrecognized selector sent to instance 0x5c07df0
2011-11-09 09:21:42.992 TestTest[543:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSURL length]: unrecognized selector sent to instance 0x5c07df0'
*** Call stack at first throw:
(
    0   CoreFoundation                      0x0102b5a9 __exceptionPreprocess + 185
    1   libobjc.A.dylib                     0x0117f313 objc_exception_throw + 44
    2   CoreFoundation                      0x0102d0bb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
    3   CoreFoundation                      0x00f9c966 ___forwarding___ + 966
    4   CoreFoundation                      0x00f9c522 _CF_forwarding_prep_0 + 50
    5   Foundation                          0x0002b1ad -[NSPathStore2 stringByAppendingPathComponent:] + 211
    6   TestTest                            0x00003244 -[Produktpalette viewDidLoad] + 535
    7   UIKit                               0x0036f089 -[UIViewController view] + 179
    8   UIKit                               0x0060ca40 -[UIPopoverController _setupIncomingViewController:presenting:animated:] + 143
    9   UIKit                               0x0060be26 -[UIPopoverController initWithContentViewController:] + 321
    10  TestTest                            0x00002540 -[TestTestViewController produktpalette:] + 151
    11  UIKit                               0x002bf4fd -[UIApplication sendAction:to:from:forEvent:] + 119
    12  UIKit                               0x004d1cc3 -[UIBarButtonItem(UIInternal) _sendAction:withEvent:] + 156
    13  UIKit                               0x002bf4fd -[UIApplication sendAction:to:from:forEvent:] + 119
    14  UIKit                               0x0034f799 -[UIControl sendAction:to:forEvent:] + 67
    15  UIKit                               0x00351c2b -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 527
    16  UIKit                               0x003507d8 -[UIControl touchesEnded:withEvent:] + 458
    17  UIKit                               0x002e3ded -[UIWindow _sendTouchesForEvent:] + 567
    18  UIKit                               0x002c4c37 -[UIApplication sendEvent:] + 447
    19  UIKit                               0x002c9f2e _UIApplicationHandleEvent + 7576
    20  GraphicsServices                    0x01983992 PurpleEventCallback + 1550
    21  CoreFoundation                      0x0100c944 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52
    22  CoreFoundation                      0x00f6ccf7 __CFRunLoopDoSource1 + 215
    23  CoreFoundation                      0x00f69f83 __CFRunLoopRun + 979
    24  CoreFoundation                      0x00f69840 CFRunLoopRunSpecific + 208
    25  CoreFoundation                      0x00f69761 CFRunLoopRunInMode + 97
    26  GraphicsServices                    0x019821c4 GSEventRunModal + 217
    27  GraphicsServices                    0x01982289 GSEventRun + 115
    28  UIKit                               0x002cdc93 UIApplicationMain + 1160
    29  TestTest                            0x00001c2a main + 84
    30  TestTest                            0x00001bcd start + 53
)
terminate called after throwing an instance of 'NSException'

感谢您提前提供的任何帮助和假设

【问题讨论】:

请同时发布崩溃日志。 我已经编辑了我的问题...见上文:) 【参考方案1】:

提示来自:

[NSURL length]: unrecognized selector sent to instance

如果你在 ios 上工作,很抱歉告诉你:

此方法在iOS中未实现,因此不执行任何操作。

有人有类似的problem。

【讨论】:

以上是关于应用程序在某行崩溃,为啥?的主要内容,如果未能解决你的问题,请参考以下文章

为啥 Chrome 会在 jQuery 中的某行暂停?

源码安装openssl时POD文件在某行有错误,error255

Matlab调试器在崩溃后显示变量

excel 查找某个字符在某行中第N次出现位置

请问,excel表格,在某行中查找某个数值对应的的列,再求此列的整列和。有啥办法。

gdbcore文件进到某行