Terminating_due_to_uncaught_exception

Discussion in 'iOS Programming' started by JavaWizKid, Aug 25, 2009.

  1. JavaWizKid macrumors 6502a

    Joined:
    Sep 18, 2008
    #1
    I can't understand this "uncaught exception" that keeps appearing. My code is here:

    Code:
    -(IBAction)musicSwitchChange:(id)sender
    {
    	if(musicSwitch.isOn)
    	{
    		[soundSwitch setOn:YES animated:YES];
    	}
    	else
    	{
    		[soundSwitch setOn:NO animated:YES];
    	}
    }
    -(IBAction)soundSwitchChange:(id)sender
    {
    	if(soundSwitch.isOn)
    	{
    		[musicSwitch setOn:YES animated:YES];
    	}
    	else
    	{
    		[soundSwitch setOn:NO animated:YES];
    	}
    }
    In Interface Builder I control drag from the files owner to the switches and define their their IBOutlets and I control drag back to the files owner from the switch and click the two functions listed above. Every time I launch the app it freezes and gives me the "TERMINATING_DUE_TO_UNCAUGHT_EXCEPTION" error in Xcode.

    Any suggestions?
     
  2. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #2
    Put a breakpoint in "objc_exception_throw" so you can see the stack trace in the debugger then, using the stack trace, click the first method that is in your code. That should help narrow it down.
     
  3. JavaWizKid thread starter macrumors 6502a

    Joined:
    Sep 18, 2008
    #3
    How do you do them? I've not done them in Objective-C before. Thanks.
     
  4. JavaWizKid thread starter macrumors 6502a

    Joined:
    Sep 18, 2008
    #5
    2009-08-25 17:45:05.712 MyApp[15233:20b] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<Menu 0xd2c920> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key musicSwitch.'
    2009-08-25 17:45:05.714 MyApp[15233:20b] Stack: (
    807902715,
    2521472571,
    808061681,
    810717848,
    810716389,
    816538544,
    807805711,
    816533170,
    816541363,
    815230552,
    815224116,
    815223834,
    11942,
    814709201,
    815110321,
    815119058,
    815114270,
    814813151,
    814722763,
    814748641,
    839148405,
    807687520,
    807683624,
    839142449,
    839142646,
    814752238,
    9448,
    9302
    )
     
  5. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #6
    Not sure if this is related but if musicSwitch and soundSwitch are instances of the UISwitch class, they don't have an isOn property. It's just on.
     
  6. JavaWizKid thread starter macrumors 6502a

    Joined:
    Sep 18, 2008
    #7
    I was messing around with that, not sure if it's the cause. I'll update you in a minute.

    Same error I think

    The Debugger has exited with status 0.
    [Session started at 2009-08-25 18:09:20 +0100.]
    2009-08-25 18:09:23.333 MyApp[15519:20b] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<Menu 0xd2c900> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key musicSwitch.'
    2009-08-25 18:09:23.335 MyApp[15519:20b] Stack: (
    807902715,
    2521472571,
    808061681,
    810717848,
    810716389,
    816538544,
    807805711,
    816533170,
    816541363,
    815230552,
    815224116,
    815223834,
    11942,
    814709201,
    815110321,
    815119058,
    815114270,
    814813151,
    814722763,
    814748641,
    839148405,
    807687520,
    807683624,
    839142449,
    839142646,
    814752238,
    9448,
    9302
    )
     
  7. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
  8. JavaWizKid thread starter macrumors 6502a

    Joined:
    Sep 18, 2008
  9. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #10
    Yeah, that's why you need to breakpoint objc_exception_throw!
     
  10. JavaWizKid thread starter macrumors 6502a

    Joined:
    Sep 18, 2008
    #11
    I thought I did :S that's what produced the error in the console wasn't it?
     
  11. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
  12. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #13
    This runtime error is caused by something not being hooked up correctly in IB. Maybe you don't have the view outlet for your view controller connected.

    In IB control-click on the File's owner and each of the views in the nib. Set the nib window View Mode to list view. In the little black window that appears check that all the connections are correct.
     
  13. JavaWizKid thread starter macrumors 6502a

    Joined:
    Sep 18, 2008
    #14
    I'm confused as to what all of these deugging methods are. I went to Run -> Manage Breakpoints -. Add Symbolic Breakpoint and put in the text box "objc_exception_throw". Where do I go from there?

    Nope, I've done that, the app still hangs. I'll try adding a button to execute a function on the same window, see if the hanging stays.

    Nope, you are right, it's a problem between IB and the ViewController. The button I added hangs too. How do I make them link properly? I control dragged from files owner to the view and clicked thew view.
     
  14. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #15
    There is some mismatch between your nib and the view controller. If you search this forum for similar exceptions or google it you'll see there are a variety of kinds of mistakes that cause the problem.

    The error is occurring when the nib loading machinery is trying to assign a value to the musicSwitch IBOutlet. It is failing because the view controller doesn't correctly have that outlet. Maybe you've set the wrong type to the view controller in IB. Is the name of your class Menu? Maybe you changed something in the header file that IB didn't get a chance to see.
     
  15. adamk77 macrumors 6502

    Joined:
    Jan 6, 2008
    #16
    In your console window, in the (gdb) line (don't quit your app), run this command. It will show you the line number.

    info line *11942
     
  16. JavaWizKid thread starter macrumors 6502a

    Joined:
    Sep 18, 2008
    #17
    My app has multiple views but the screen that isn't working is the options one. The Inspector says everything is correct :S
     

    Attached Files:

  17. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #18
    What is the class called Menu?

    So this happens when you are pushing a view controller not when the app starts up?

    The nib-loading machinery thinks that the class called Menu should have the musicSwitch outlet but you show that the class is called Options.
     
  18. JavaWizKid thread starter macrumors 6502a

    Joined:
    Sep 18, 2008
    #19
    Menu is the screen that links to the other screens via the switchViewConroller class.
     
  19. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #20
    OK. So that class doesn't have the outlet musicSwitch. That is the cause of the run-time exception. You need to look at your code and your nib file and see why the system is trying to make a Menu object when it should be making an Options object.
     
  20. JavaWizKid thread starter macrumors 6502a

    Joined:
    Sep 18, 2008
    #21
    I don't understand how it isn't linked. I control dragged the IBOutlets to their functions. I dragged from files owner to the IBOutlets to declare them. The Files owner is the Options class and I have control dragged from files owner to the view and selected view.
     
  21. JavaWizKid thread starter macrumors 6502a

    Joined:
    Sep 18, 2008
    #22
    It must be something to do with the class relation to the xib file. I removed al the code and replaced it with a simple button to make a pop up window appear:

    Code:
    #import <UIKit/UIKit.h>
    
    
    @interface Options : UIViewController {
    
    }
    
    -(IBAction)butonPressed:(id)sender;
    
    @end
    
    
    
    
    #import "Options.h"
    
    
    @implementation Options
    
    -(IBAction)butonPressed:(id)sender
    {
    	UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Button Pressed" message:@"Button was pressed" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
    	[alert show];
    	[alert release];
    }
    
    /*
     // The designated initializer.  Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
    - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
        if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
            // Custom initialization
        }
        return self;
    }
    */
    
    /*
    // Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
    - (void)viewDidLoad {
        [super viewDidLoad];
    }
    */
    
    /*
    // Override to allow orientations other than the default portrait orientation.
    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
        // Return YES for supported orientations
        return (interfaceOrientation == UIInterfaceOrientationPortrait);
    }
    */
    
    - (void)didReceiveMemoryWarning {
    	// Releases the view if it doesn't have a superview.
        [super didReceiveMemoryWarning];
    	
    	// Release any cached data, images, etc that aren't in use.
    }
    
    - (void)viewDidUnload {
    	// Release any retained subviews of the main view.
    	// e.g. self.myOutlet = nil;
    }
    
    
    - (void)dealloc {
        [super dealloc];
    }
    
    
    @end
    
    
    The code is bugproof and I control dragged from the button in the xib file to teh files owner file and selected the function. I then dragged from files owner to the view and selected view. Compiled and ran, app hangs when the button is pushed with "TERMINATING_DUE_TO_UNCAUGHT_EXCEPTION".
     
  22. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #23
    If you're willing, zip up your project and attach it and maybe I (or someone else) can have a look at it, if we get a chance.
     

Share This Page