ios - 由于未捕获的异常而终止应用程序。 "nil string parameter"

标签 ios objective-c crash viewdidload xcode5.1

今天早上我的应用程序运行良好。我更新到 Xcode 5.1,当我运行我的应用程序时,当我点击播放时它崩溃了。我的应用程序有一个模式按钮,可通往另一个 View Controller 。第一个 View Controller 是主屏幕。我启动应用程序,按下播放按钮,然后它大约一秒钟什么都不做(而不是带我到第二个 View Controller ,即游戏本身),然后 Xcode 将我带到 main.m。这就是我的 main.m 的样子(没有修改)。因此,当 Xcode 将我带到这里时,以 return UIApplicationMain 开头的行以绿色突出显示,最右侧显示 thread 1: signal SIGABRT

#import <UIKit/UIKit.h>

#import "AppDelegate.h"

int main(int argc, char * argv[])
{
    @autoreleasepool {
       return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
    }
}

有人对正在发生的事情有什么建议吗?

------已更新

我不确定这是否有帮助(因为我仍然是初学者,但我认为就是这样)。它说:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSURL initFileURLWithPath:]: nil string parameter' *** First throw call stack:

(
    0   CoreFoundation                      0x01f0c1e4 __exceptionPreprocess + 180
    1   libobjc.A.dylib                     0x0180a8e5 objc_exception_throw + 44
    2   CoreFoundation                      0x01f0bfbb +[NSException raise:format:] + 139
    3   Foundation                          0x0142692b -[NSURL(NSURL) initFileURLWithPath:] + 123
    4   Foundation                          0x014267fd +[NSURL(NSURL) fileURLWithPath:] + 67
    5   Bad Jetpack Complete                0x00004f92 -[Game viewDidLoad] + 1170
    6   UIKit                               0x005e933d -[UIViewController loadViewIfRequired] + 696
    7   UIKit                               0x005e95d9 -[UIViewController view] + 35
    8   UIKit                               0x005f8f89 -[UIViewController shouldAutorotate] + 36
    9   UIKit                               0x005f92d1 -[UIViewController _preferredInterfaceOrientationForPresentationInWindow:fromInterfaceOrientation:] + 297
    10  UIKit                               0x008973d5 -[UIWindowController transition:fromViewController:toViewController:target:didEndSelector:animation:] + 2330
    11  UIKit                               0x005f55d5 -[UIViewController presentViewController:withTransition:completion:] + 6538
    12  UIKit                               0x005f5aef -[UIViewController presentViewController:animated:completion:] + 130
    13  UIKit                               0x005f5b2f -[UIViewController presentModalViewController:animated:] + 56
    14  UIKit                               0x00a3fe00 -[UIStoryboardModalSegue perform] + 271
    15  UIKit                               0x00a2ef0c -[UIStoryboardSegueTemplate _perform:] + 174
    16  UIKit                               0x00a2ef87 -[UIStoryboardSegueTemplate perform:] + 115
    17  libobjc.A.dylib                     0x0181c880 -[NSObject performSelector:withObject:withObject:] + 77
    18  UIKit                               0x004cc3b9 -[UIApplication sendAction:to:from:forEvent:] + 108
    19  UIKit                               0x004cc345 -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 61
    20  UIKit                               0x005cdbd1 -[UIControl sendAction:to:forEvent:] + 66
    21  UIKit                               0x005cdfc6 -[UIControl _sendActionsForEvents:withEvent:] + 577
    22  UIKit                               0x005cd243 -[UIControl touchesEnded:withEvent:] + 641
    23  UIKit                               0x0050bddd -[UIWindow _sendTouchesForEvent:] + 852
    24  UIKit                               0x0050c9d1 -[UIWindow sendEvent:] + 1117
    25  UIKit                               0x004de5f2 -[UIApplication sendEvent:] + 242
    26  UIKit                               0x004c8353 _UIApplicationHandleEventQueue + 11455
    27  CoreFoundation                      0x01e9577f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
    28  CoreFoundation                      0x01e9510b __CFRunLoopDoSources0 + 235
    29  CoreFoundation                      0x01eb21ae __CFRunLoopRun + 910
    30  CoreFoundation                      0x01eb19d3 CFRunLoopRunSpecific + 467
    31  CoreFoundation                      0x01eb17eb CFRunLoopRunInMode + 123
    32  GraphicsServices                    0x030885ee GSEventRunModal + 192
    33  GraphicsServices                    0x0308842b GSEventRun + 104
    34  UIKit                               0x004caf9b UIApplicationMain + 1225
    35  Bad Jetpack Complete                0x00002e7d main + 141
    36  libdyld.dylib                       0x03c7f701 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb) 

- (void)viewDidLoad

{

CactusTop.hidden = YES;
CactusBottom.hidden = YES;

ScoreLabel.hidden = YES;
GameOverScreen.hidden = YES;
RestartButton.hidden = YES;
LeaderBoardButton.hidden = YES;
ScoreLabel2.hidden = YES;
HighscoreLabel.hidden = YES;
RestartButton.hidden = YES;

HighScoreNumber = [[NSUserDefaults standardUserDefaults] integerForKey:@"HighScoreSaved"];

NSURL *ClickURL = [NSURL fileURLWithPath:[[NSBundle mainBundle]  pathForResource:@"Click"ofType:@"mp3"]];
AudioServicesCreateSystemSoundID((__bridge CFURLRef)ClickURL, &  ClickSound);


NSURL *ExplosionURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"Explosion" ofType:@"mp3"]];
ExplosionSound = [[AVAudioPlayer alloc] initWithContentsOfURL:ExplosionURL error:nil];
[ExplosionSound setNumberOfLoops:0];
[ExplosionSound prepareToPlay];

NSURL *JetpackURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"Jetpack 1_2sec_01c" ofType:@"mp3"]];
JetpackSound = [[AVAudioPlayer alloc] initWithContentsOfURL:JetpackURL error:nil];
[JetpackSound setNumberOfLoops:0];
[JetpackSound prepareToPlay];

NSURL *PointURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"Point" ofType:@"mp3"]];
PointSound = [[AVAudioPlayer alloc] initWithContentsOfURL:PointURL error:nil];
[PointSound setNumberOfLoops:0];
[PointSound prepareToPlay];

这是 View 加载后的更新问题

最佳答案

好的,在您的应用程序中的某个位置,您尝试从 URL 加载文件,但 URL 为零。

你能显示一下你在哪里执行此操作的代码吗?这将有助于回答您的问题。

实际上,它位于文件Game.m中的方法- (void)viewDidLoad;中。

关于ios - 由于未捕获的异常而终止应用程序。 "nil string parameter",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22751714/

相关文章:

iOS通知内容扩展: add buttons in storyboard and handle the click action

ios - 在 iOS 中从 .xib 文件调用 UIViewController 时尝试传递 UIButton 的标记值

ios - iOS 7 中的 UIActivityViewController 奇怪行为

c# - 如果我在重新启动时启动我的应用程序,MyApp 会在几秒钟后崩溃

android - 类中的 TextView 和 setText

java - 尝试存储SQLite数据时,我的Android应用程序崩溃

ios - 获取 SwiftUI 中 List 的内容偏移量

ios - 奥林巴斯相机套件 : App exits when it draws face detection frame on the live view

ios - Google Analytics 在 iOS 中未发送任何点击?

ios - 从调用方 View 设置 UITextField 的文本