[__NSArrayM insertObject:atIndex:]: object cannot

2019-09-12 17:37发布

问题:

For some reason that I cannot find I am getting the following error:

Terminating app due to uncaught exception 'NSInvalidArgumentException', 
reason: '*** -[__NSArrayM insertObject:atIndex:]: object cannot be nil'

As I am quite new in xCode i'd like some help. The application crashes in the following line:

[self.window makeKeyAndVisible];

in the ASAppDelegate.m file.

The whole function is like this:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.

AS_MainViewController *MyrootViewController = [[AS_MainViewController alloc]
                        initWithNibName:@"AS_MainViewController" bundle: [NSBundle mainBundle]];

self.window.rootViewController = MyrootViewController;

self.window.backgroundColor = [UIColor whiteColor];

return YES;
}

Could you please help me?

Thank you.

回答1:

finally the error has been resolved. I started a new empty project and did all the work from the beginning. As I was also copy-pasting from the old one, step by step I was also running each time in every step. The application run without problems. I finished it and now it runs. I could ever understand why and what this error was, but in a new project (having the same code with the old one) the problem does not exist!

Anyway, thank you for your help.