Thread 1: Program received signal: "SIGABRT".

Discussion in 'iOS Programming' started by lJoct03, Oct 18, 2011.

  1. lJoct03 macrumors member

    Joined:
    Nov 18, 2009
  2. jiminaus macrumors 65816

    jiminaus

    Joined:
    Dec 16, 2010
    Location:
    Sydney
    #2
    SIGABRT means you've tried to access an invalid pointer somewhere in your program. This is one of the hardest things to diagnose through a forum because the scope of the error is so large.

    Start by switching to the LLDB debugger. In my experience, the LLDB debugger is more likely to stop at the line where the invalid access happens than GDB will.

    To change to the LLDB debugger (assuming your using XCode 4.x).

    1. Click the left-hand side of scheme popup menu in the toolbar.
    2. Edit Scheme...
    3. Under the Info tab, changed debugger from GDB to LLDB.

    Rerun the program. Where does it now stop?
     
  3. jonnymo5 macrumors 6502

    Joined:
    Jan 21, 2008
    Location:
    Texas
    #3
    Test early, test often. The smaller your changeset the easier time you will have hunting down this kind of issue.
     
  4. lJoct03 thread starter macrumors member

    Joined:
    Nov 18, 2009
    #4
    this is what i get now:
     

    Attached Files:

  5. jiminaus macrumors 65816

    jiminaus

    Joined:
    Dec 16, 2010
    Location:
    Sydney
    #5
    Do you see the dashed line between the two stack frames? This dashed line represents hidden stack frames.

    You'll see a slider at the bottom of the thread view pane. Slide it to the left (I think) until you see the full stack trace; that is, until you don't see a dashed line between two stack frames.
     
  6. lJoct03 thread starter macrumors member

    Joined:
    Nov 18, 2009
    #6
    ok i did it.
    here it is:

    what now?

    PS: thanks for the help!!!
     

    Attached Files:

  7. jiminaus macrumors 65816

    jiminaus

    Joined:
    Dec 16, 2010
    Location:
    Sydney
    #7
    I don't know. The stack trace doesn't give me any clues. It is weird though that before the bottom of the stack trace was std::terminate and now it's not. Are you using any C++ code in your project?

    I would perhaps put a breakpoint in your app delegate's application:didFinishLaunchingWithOptions: and see if it hits it. If it does hit it, step through and see what happens.
     
  8. lJoct03 thread starter macrumors member

    Joined:
    Nov 18, 2009
    #8
    okay thanks!
    i'll try that right now.
    this is going to sound stupid, but how to i create a breakpoint?
    do i just press the button next to the line?
     
  9. lJoct03 thread starter macrumors member

    Joined:
    Nov 18, 2009
    #9
    HERE IS THE CODE

    Code:
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
        // Override point for customization after application launch.
        [window addSubview:rootController.view];
        [self.window addSubview:[navigationController view]];
        [self.window makeKeyAndVisible];
        return YES;
        
        // Add the tab bar controller's current view as a subview of the window
        self.window.rootViewController = self.tabBarController;
        return YES;
        
    }
    What do i fill in for the condition, ignore, and action?
     

    Attached Files:

  10. jiminaus macrumors 65816

    jiminaus

    Joined:
    Dec 16, 2010
    Location:
    Sydney
    #10
    Yeap, that's one way.
     
  11. lJoct03 thread starter macrumors member

    Joined:
    Nov 18, 2009
    #11
    What do i fill in for the condition, ignore, and action?
     

    Attached Files:

  12. jnoxx macrumors 65816

    jnoxx

    Joined:
    Dec 29, 2010
    Location:
    Aartselaar // Antwerp // Belgium
    #12
    Code:
        // Override point for customization after application launch.
        [window addSubview:rootController.view];
        [self.window addSubview:[navigationController view]];
        [self.window makeKeyAndVisible];
        return YES;
        
        // Add the tab bar controller's current view as a subview of the window
        self.window.rootViewController = self.tabBarController;

    Errrr, sorry my man, but your code is utterly random.
    You add a rootController.view, then you add a navigation, and after you return "yes", you try to add a tabbar too to the mainwindow. Which never works after a return anyway.
    So seriously, have u thought about your flow, or even remotely looked up what are the standard flows in the iOS Environment? Pick one, and build on that, i think that will help you better.
     
  13. lJoct03 thread starter macrumors member

    Joined:
    Nov 18, 2009
    #13
    This is my code now:

    Code:
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
        // Override point for customization after application launch.
        UIViewController *rootController = [[RootViewController alloc] init];
        navigationController = [[UINavigationController alloc] initWithRootViewController:rootController];
        [rootController release];
        window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
        [window addSubview:navigationController.view];
        
        // Add the tab bar controller's current view as a subview of the window
        self.window.rootViewController = self.tabBarController;
        [self.window makeKeyAndVisible];
        return YES;
        
        
    }
    Still get the same error.
    What should i do now?
    Any help?
     
  14. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #14
    Dude. A sigabrt is the system helping you. There is a bug in your code. The system has recognized this immediately. It throws an exception that results in the SIGABRT. When this happens you need to look at the text in the debugger console. That is where the elves inside the system tell you what bug they found.

    Look for the text that starts "Terminating app..." Post it here. Also the breakpoint on the exception throw will show you exactly which line of code in your app has made the boo boo.
     
  15. jnoxx macrumors 65816

    jnoxx

    Joined:
    Dec 29, 2010
    Location:
    Aartselaar // Antwerp // Belgium
    #15
    Have you listened to what i say? i actually told you what to do, but you're a bit stubborn on picking up a book huh? These are basic principles of iOS Development, even if you can get this sketchy working, you will have major memory issues etc etc.
     
  16. lJoct03 thread starter macrumors member

    Joined:
    Nov 18, 2009
    #16

    Where do i find the text that says "Terminating app..."?
     
  17. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #17
    Here:
     
  18. lJoct03 thread starter macrumors member

    Joined:
    Nov 18, 2009
    #18
    This is what i got:

     
  19. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
  20. lJoct03 thread starter macrumors member

    Joined:
    Nov 18, 2009
    #20
    I have no idea!
    Any help?
    Thanks!!!
     
  21. jnoxx macrumors 65816

    jnoxx

    Joined:
    Dec 29, 2010
    Location:
    Aartselaar // Antwerp // Belgium
    #21
    I'm really sorry but, and I quote
    It says: reason, you're trying to call objectForKey (which is used on Dictionary's and such) on an String.
    Tadaaaa, rocket science up in this thread!
    And that no offense to you, but, Dejo is trying his hardest best to be nice to everyone on this forum with such questions. but the answer is like right there..
     
  22. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #22
    The unrecognized selector error is a runtime exception. It means that some code tried to call a method on an object and that object doesn't implement that method. In this case the app tried to call objectForKey on a NSString object. objectForKey is an NSDictionary method, not found in NSString.

    This generally happens one of two ways. 1) you do have explicit code that mistakenly calls objectForKey on a string object. You might put strings into an array and then later iterate over them and treat them as dictionaries, or something like that. Does your code have any calls to objectForKey?

    2) Improper memory management can result in an object being replaced in memory with another object. If your code doesn't retain an ivar correctly then the memory used by that ivar can be replaced with another object of another type. Later when you attempt to use the ivar this new object tells you that it doesn't respond to the selector and the little man gives you the SIGABRT. This happens frequently with new coders as they don't understand memory management very well.

    If you've set the exception breakpoint mentioned above this should help you to track down the line of code that is causing the problem so you can figure it out.
     
  23. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #23
    I guess now would be as good a time as any to learn some debugging skills.
     
  24. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #24
    A typical debugging tool for finding such errors is to run under Instruments with zombies enabled.
    One way to learn how to do that is to google: ios instruments zombies.
     
  25. lJoct03 thread starter macrumors member

    Joined:
    Nov 18, 2009
    #25
    My code calls objectForKey 4 times:
    (all in RootViewController.m)

    Code:
    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
        if (searching)
            return [copyListOfItems count];
        else {
        
        //Number of rows it should expect should be based on the section
        NSDictionary *dictionary = [listOfItems objectAtIndex:section];
        NSArray *array = [dictionary objectForKey:@"News"];
        return [array count];
        
        }
    }
    Code:
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
        
        static NSString *CellIdentifier = @"Cell";
        
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        if (cell == nil) {
           cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
        }
        
        // Set up the cell...
        if(searching) 
            cell.textLabel.text = [copyListOfItems objectAtIndex:indexPath.row];
        else {
        //First get the dictionary object
    	NSDictionary *dictionary = [listOfItems objectAtIndex:indexPath.section];
        NSArray *array = [dictionary objectForKey:@"News"];
        NSString *cellValue = [array objectAtIndex:indexPath.row];
        cell.textLabel.text = cellValue;
        }
        return cell;
        
    }
    Code:
    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
        
        //Get the selected country
        
        NSString *selectedNews = nil;
        
        if(searching)
            selectedNews = [copyListOfItems objectAtIndex:indexPath.row];
        else {
            
            NSDictionary *dictionary = [listOfItems objectAtIndex:indexPath.section];
            NSArray *array = [dictionary objectForKey:@"News"];
            selectedNews = [array objectAtIndex:indexPath.row];
        }
        
        //Initialize the detail view controller and display it.
        DetailViewController *dvController = [[DetailViewController alloc] initWithNibName:@"DetailView" bundle:[NSBundle mainBundle]];
        dvController.selectedNews = selectedNews;
        [self.navigationController pushViewController:dvController animated:YES];
        [dvController release];
        dvController = nil;
    }

    Code:
    - (void) searchTableView {
        
        NSString *searchText = searchBar.text;
        NSMutableArray *searchArray = [[NSMutableArray alloc] init];
        
        for (NSDictionary *dictionary in listOfItems)
        {
            NSArray *array = [dictionary objectForKey:@"News"];
            [searchArray addObjectsFromArray:array];
        }
        
        for (NSString *sTemp in searchArray)
        {
            NSRange titleResultsRange = [sTemp rangeOfString:searchText options:NSCaseInsensitiveSearch];
            
            if (titleResultsRange.length > 0)
                [copyListOfItems addObject:sTemp];
        }
        
        [searchArray release];
        searchArray = nil;
    }
     

Share This Page