Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IOS [__NSPlaceholderArray initWithObjects:count:]: attempt to insert nil object from objects[0]'

I am trying to create a dynamic slide menu like facebook.

I have to get some data from a json request. and display this data in one of the sections of the slide table view. I'm new in objective-c, I also tried with NSMutableArrays and I had an error. In other table views I do the same but without sections. only one MutableArray and I can show the table.

I do something like this:

-(void) requestJSONFinishedWithParsedObject:(NSDictionary *)parsedObject{


  NSArray  *projectsObjectArray = [parsedObject objectForKey:@"projects"];

    [self createMainNavigationController];
    self.section1 = [NSArray arrayWithObjects:@"Profile", @"Notifications", @"Exit", nil];
    self.section2 = [NSArray arrayWithObjects:@"Main", nil];


    for (NSDictionary *projectObject in projectsObjectArray)
    {
        Project *newProject = [[Project alloc] init];

        newProject.title= [projectObject objectForKey:@"title"];

        self.section3 = [NSArray arrayWithObject:newProject.title];
    }

    self.menu = [NSArray arrayWithObjects:self.section1, self.section2, self.section3, nil];
    [menuTableView reloadData];
}

I am having this error :

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSPlaceholderArray initWithObjects:count:]: attempt to insert nil object from objects[0]'
like image 696
roxeman3 Avatar asked May 03 '13 18:05

roxeman3


1 Answers

It is because

newProject.title= [projectObject objectForKey:@"title"];

is nil, and you are trying to add it to the array. Check to see what that value is by logging it

NSLog(@"%@", [projectObject objectForKey:@"title"]);
like image 86
JeffN Avatar answered Sep 20 '22 20:09

JeffN