Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

JavaWizKid

macrumors 6502a
Original poster
Sep 18, 2008
572
0
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?
 

JavaWizKid

macrumors 6502a
Original poster
Sep 18, 2008
572
0
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
)
 

dejo

Moderator emeritus
Sep 2, 2004
15,982
452
The Centennial State
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.
 

JavaWizKid

macrumors 6502a
Original poster
Sep 18, 2008
572
0
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
)
 

PhoneyDeveloper

macrumors 68040
Sep 2, 2008
3,114
93
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.
 

JavaWizKid

macrumors 6502a
Original poster
Sep 18, 2008
572
0
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?

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.

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.
 

PhoneyDeveloper

macrumors 68040
Sep 2, 2008
3,114
93
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.
 

JavaWizKid

macrumors 6502a
Original poster
Sep 18, 2008
572
0
My app has multiple views but the screen that isn't working is the options one. The Inspector says everything is correct :S
 

Attachments

  • Picture 2.png
    Picture 2.png
    84.8 KB · Views: 46

PhoneyDeveloper

macrumors 68040
Sep 2, 2008
3,114
93
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.
 

JavaWizKid

macrumors 6502a
Original poster
Sep 18, 2008
572
0
Menu is the screen that links to the other screens via the switchViewConroller class.
 

PhoneyDeveloper

macrumors 68040
Sep 2, 2008
3,114
93
Menu is the screen that links to the other screens via the switchViewConroller class.

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.
 

JavaWizKid

macrumors 6502a
Original poster
Sep 18, 2008
572
0
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.
 

JavaWizKid

macrumors 6502a
Original poster
Sep 18, 2008
572
0
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".
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.