3

I'm new to ios development and to stackoverflow. I did try searching both stackoverflow and google before posting.

I built a simple little app, originally just left it an iphone only app, but decided to make it universal in the end. I, stupidly, was messing around when i was getting to know xcode 4 and switched it to universal and then back again so i had to recopy the project and do it again. This time i started it with a universal app. (Not when i created it but after i went to project and selected it there) It created the ipad folder and mainwindow-ipad.xib file but was empty of course since i didn't do anything yet. I had it set up as a tabbed based app so my iphone version had firstview and secondview nib files also, but the ipad version didn't. I set it all up in iphone version first and it worked fine. I then went and laid down the ipad version (i did eliminate the second tab from mainwindow-ipad because i didn't need it)

i then went and created a new nib file and placed it in the ipad folder along with "main-ipad.h" and "main-ipad.m". I copied my code and connected everything and it runs fine on ipad simulator but now when i try and run iphone simulator i get "SIGABRT error. I took a screen shot of it. I don't fully understand objective-c so i was hoping someone can help me? I can post any code or whatever you might need to help me with this error so just ask.

Appreciate any help and suggestions you may have!

Thanks!

[Okay i would have posted image but I can't since I'm a new user, instead i posted the line highlighted and the output from xcode]

Code for file with error:

int main(int argc, char *argv[])
{
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    int retVal = UIApplicationMain(argc, argv, nil, nil); //ERROR IS ON THIS LINE <-----
    [pool release];
    return retVal;
}

[OUTPUT]

2011-06-18 17:32:43.980 Price Assist[445:207] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<UIViewController 0x4e09cc0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key finallabel.'
*** Call stack at first throw:
(
0   CoreFoundation                      0x00dc35a9 __exceptionPreprocess + 185
1   libobjc.A.dylib                     0x00f17313 objc_exception_throw + 44
2   CoreFoundation                      0x00dc34e1 -[NSException raise] + 17
3   Foundation                          0x00795677 _NSSetUsingKeyValueSetter + 135
4   Foundation                          0x007955e5 -[NSObject(NSKeyValueCoding) setValue:forKey:] + 285
5   UIKit                               0x0021130c -[UIRuntimeOutletConnection connect] + 112
6   CoreFoundation                      0x00d398cf -[NSArray makeObjectsPerformSelector:] + 239
7   UIKit                               0x0020fd23 -[UINib instantiateWithOwner:options:] + 1041
8   UIKit                               0x00211ab7 -[NSBundle(UINSBundleAdditions) loadNibNamed:owner:options:] + 168
9   UIKit                               0x000c7628 -[UIViewController _loadViewFromNibNamed:bundle:] + 70
10  UIKit                               0x000c5134 -[UIViewController loadView] + 120
11  UIKit                               0x000c500e -[UIViewController view] + 56
12  UIKit                               0x00038d42 -[UIWindow addRootViewControllerViewIfPossible] + 51
13  Foundation                          0x007955e5 -[NSObject(NSKeyValueCoding) setValue:forKey:] + 285
14  UIKit                               0x00048ff6 -[UIView(CALayerDelegate) setValue:forKey:] + 173
15  UIKit                               0x0021130c -[UIRuntimeOutletConnection connect] + 112
16  CoreFoundation                      0x00d398cf -[NSArray makeObjectsPerformSelector:] + 239
17  UIKit                               0x0020fd23 -[UINib instantiateWithOwner:options:] + 1041
18  UIKit                               0x00211ab7 -[NSBundle(UINSBundleAdditions) loadNibNamed:owner:options:] + 168
19  UIKit                               0x0001717a -[UIApplication _loadMainNibFile] + 172
20  UIKit                               0x00017cf4 -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 291
21  UIKit                               0x00022617 -[UIApplication handleEvent:withNewEvent:] + 1533
22  UIKit                               0x0001aabf -[UIApplication sendEvent:] + 71
23  UIKit                               0x0001ff2e _UIApplicationHandleEvent + 7576
24  GraphicsServices                    0x00ffc992 PurpleEventCallback + 1550
25  CoreFoundation                      0x00da4944 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52
26  CoreFoundation                      0x00d04cf7 __CFRunLoopDoSource1 + 215
27  CoreFoundation                      0x00d01f83 __CFRunLoopRun + 979
28  CoreFoundation                      0x00d01840 CFRunLoopRunSpecific + 208
29  CoreFoundation                      0x00d01761 CFRunLoopRunInMode + 97
30  UIKit                               0x000177d2 -[UIApplication _run] + 623
31  UIKit                               0x00023c93 UIApplicationMain + 1160
32  Price Assist                        0x000029a9 main + 121
33  Price Assist                        0x00002925 start + 53
)
terminate called after throwing an instance of 'NSException'

iPhone FirstView nib file .h code:

@interface FirstViewController : UIViewController {
    IBOutlet UITextField *dollarinput;
    IBOutlet UITextField *centsinput;
    IBOutlet UIButton *combinevalue;
    IBOutlet UITextField *percentoffinput;
    IBOutlet UILabel *discountlabel;
    IBOutlet UILabel *finallabel;
}  
- (IBAction)calculate:(id)sender;
- (IBAction)backgroundTouched:(id)sender;
- (IBAction)autonext:(id)sender;

iPhone FirstView nib file .m code:

//
//  FirstViewController.m
//  Price Assist
//
//  Created by Dustin Schreiber on 6/15/11.
//  Copyright 2011 TheTechSphere.com. All rights reserved.
//

#import "FirstViewController.h"


@implementation FirstViewController

/*
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad
{
[super viewDidLoad];
}
*/

- (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
{    
[percentoffinput release];
percentoffinput = nil;
[discountlabel release];
discountlabel = nil;
[finallabel release];
finallabel = nil;
[super viewDidUnload];

// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}


- (void)dealloc
{
[percentoffinput release];
[discountlabel release];
[finallabel release];
[super dealloc];
}


- (IBAction)calculate:(id)sender {
if ([centsinput.text length] == 0){
    centsinput.text = @"00";
}
if ([dollarinput.text length] == 0){
    dollarinput.text = @"00";
}
if ([percentoffinput.text length] == 0){
    percentoffinput.text = @"00";
}
double cDollars = [dollarinput.text doubleValue];
double cCents = [centsinput.text doubleValue];
double percentoff = [percentoffinput.text doubleValue] / 100;
NSString *ccDollars = [[NSNumber numberWithFloat:cDollars] stringValue];
NSString *ccCents = [[NSNumber numberWithFloat:cCents] stringValue];
NSString *placeholder = [NSString stringWithFormat:@"%@.%@", ccDollars, ccCents];
double combined = [placeholder doubleValue];
double discount = combined * percentoff;
NSString *discountholder2 =[NSString stringWithFormat:@"%.2f", discount];
discountlabel.text = discountholder2;
double newprice = (combined - discount);
NSString *str = [NSString stringWithFormat:@"%.2f", newprice];
finallabel.text = str;
dollarinput.text = ccDollars;
centsinput.text = ccCents;
percentoffinput.text = [[NSNumber numberWithFloat:percentoff] stringValue];
}

-(IBAction)backgroundTouched:(id)sender
{
[dollarinput resignFirstResponder];
[centsinput resignFirstResponder];
[percentoffinput resignFirstResponder];
}

- (IBAction)autonext:(id)sender {
if ([centsinput.text length ] >= 2) {
    if ([centsinput.text length] > 2) {
        centsinput.text = @"";
    } else {
        //next field
    }
}
}

@end

Thanks again! If anyone has any suggestions for my code i'd love to here them! Like I said, I'm new to it and thats the only way i know to do this.

------------> If anyone wants, I'll upload the entire project folder. Just ask. Thank you guys for all the help. i'm a n00b with xcode so i haven't got it all down yet.

Project Zipped

ReArmedHalo
  • 35
  • 1
  • 1
  • 6
  • Post some code where you use `finallabel` and try to debug your app so you can tell me the line just before the app crashes. – Nicolas S Jun 18 '11 at 20:28
  • By adding a breakpoint to [NSException raise] and objc_exception_throw, you will have more information on the reason of your crash. More details here : http://chanson.livejournal.com/171198.html – Julien Jun 18 '11 at 20:34
  • Thanks! Code for the file that contains the error. I'll comment again for next part to your requests – ReArmedHalo Jun 18 '11 at 20:37

4 Answers4

2

Post some code where you use finallabel and try to debug your app so you can tell me the line just before the app crashes.

Option 2: Try to set a BreakPoint in malloc_error_break so we can have more info about the error.

In XCode go to Run -> Show -> BreakPoints (or just cmd + option + B). Then double click to add a new symbol (symbolic breakpoint) and type in malloc_error_break then press enter.

Now run your app and paste your console text.

UPDATE If you need help http://developer.apple.com/library/mac/#recipes/xcode_help-breakpoint_navigator/articles/adding_a_symbolic_breakpoint.html


Check your connections inside your InterfaceBuilder, you may have it wrong with fianllabel. Also check your Custom Class -> Class in your iphone XIB in your InterfaseBuilder


UPDATE

Go to Product -> Clean. Then Run.

Nicolas S
  • 5,325
  • 3
  • 29
  • 36
  • Where do i double click to add the break point? Which line should i put it on? – ReArmedHalo Jun 18 '11 at 20:44
  • you should double click any empty line, what version of XCode are you using? – Nicolas S Jun 18 '11 at 20:45
  • Okay i will. Thank you for your help so far. I am going to eat dinner so i'll return and try that after. Should i put the break point in the file before it errors? – ReArmedHalo Jun 18 '11 at 20:54
  • You should set a symbolic breakpoint in malloc_error_break first, and run the app, if no good info, you can then set a breakpoint in some part prior to your crash and debug step by step until you hit the line where your app crashes. – Nicolas S Jun 18 '11 at 20:58
  • Set a breakpoint in this line `- (IBAction)calculate:(id)sender {` Then run your app and click that button, then step into (step by step) and tell me which line is the one just before the app crashes – Nicolas S Jun 18 '11 at 21:46
  • I can't seem to find malloc_error_break line in the code anywhere? Ill try searching google to see if i am just misunderstanding that. I set the breakpoint two lines above the one that errors but i'm not sure what i should do after i run it with breakpoints? I know how to use them in vb.net but it runs fine up until the error line. Thing thats has me is that the ipad simulator uses the same exact code for my ibactions and the labels and everything is the same, all i did was modify the layout? And remove the secondview – ReArmedHalo Jun 18 '11 at 21:47
  • ok paste the header of your .m file to have a look at your class related stuff – Nicolas S Jun 18 '11 at 21:53
  • @Nicolas S - I posted it in the original post. Is that the file you were asking for? – ReArmedHalo Jun 18 '11 at 22:02
  • Humm yes, but the header where you have something like: #import "asdfasdfas.h" @implementation asdfasdf – Nicolas S Jun 18 '11 at 22:03
  • How about now? @Nicolas S - Again thank you everyone for the help – ReArmedHalo Jun 18 '11 at 22:15
  • I missed this "Set a breakpoint in this line - (IBAction)calculate:(id)sender { Then run your app and click that button, then step into (step by step) and tell me which line is the one just before the app crashes" but i am not even able to run it, i press run and it says attching then running then my error happens. – ReArmedHalo Jun 18 '11 at 22:20
  • oh then do what i say in my answer, the last bit – Nicolas S Jun 18 '11 at 22:22
  • I can't get the app to run at all. It doesn't display at all for iphone. iPad it works the way it should. – ReArmedHalo Jun 18 '11 at 22:25
  • Ok go to your iphone XIB and check all your connections and your Custom Class -> Class of evrything – Nicolas S Jun 18 '11 at 22:29
  • As far as i can tell, everything looks connected to where it should. Also as far as i can see, the connections are exactly the same for the ipad nib file also. could i have done something with the ipad version that makes the iphone version not run? – ReArmedHalo Jun 18 '11 at 22:33
  • Yes exactly, check your connections based on your iphone one, you do have two different .m and .h files right? – Nicolas S Jun 18 '11 at 22:35
  • Do you have your custom class set correctly within your iphone and ipad XIB, these should be different. – Nicolas S Jun 18 '11 at 22:37
  • yes i made the ipad one when i added the nib file (xcode did it when i added it) - the second screen shot shows all my files. – ReArmedHalo Jun 18 '11 at 22:38
  • ok ive seen it, but Do you have your custom class set correctly within your iphone and ipad XIB?, these should be different – Nicolas S Jun 18 '11 at 22:39
  • if your prefer just zip and upload yur project folder and i can have a look – Nicolas S Jun 18 '11 at 22:45
  • Maybe i don't? I didn't think i used custom classes. I thought all i used was IBActions and IBOutlets? – ReArmedHalo Jun 18 '11 at 22:46
  • Okay, i will. I just looked at the ipad "identity inspector" tab and custom class has FirstViewController set there (this is for mainwindow-ipad, and i clicked on tab bar conroller then first view controller), but that is for the iphone one right? The iphone has the same selected which also confused me since it works for ipad but not iphone when using the same custom class. Ill zip it up and upload it now post link in a minute. – ReArmedHalo Jun 18 '11 at 22:51
  • YOur `FirstViewController` is a custom Class though, you are sublassing `UIViewController` – Nicolas S Jun 18 '11 at 22:51
  • Uploaded and link is in the main post – ReArmedHalo Jun 18 '11 at 22:56
  • ok i will download, i think the error is in your tabBarController. – Nicolas S Jun 18 '11 at 22:57
  • humm it is not posted.. i cant find it – Nicolas S Jun 18 '11 at 22:58
  • Sorry i forgot to press save. Its there now – ReArmedHalo Jun 18 '11 at 22:59
  • Just realized. It hasn't finished uploading. The sound i heard must have been some other app. Its halfway. I'm on a slow connection right now – ReArmedHalo Jun 18 '11 at 22:59
  • It's done. Thank you for taking the time to help me out. Appreciate it. – ReArmedHalo Jun 18 '11 at 23:05
  • You are welcome, i have been helped like this before and i think its nice when people help each other – Nicolas S Jun 18 '11 at 23:10
  • Yes, the main reason i joined StackOverflow because i noticed i found lots of answer for xcode related things here so i decided to join so i can get and give help to the community. :) – ReArmedHalo Jun 18 '11 at 23:12
  • I dont know why but it is taking too long to download, ill tell you when its done – Nicolas S Jun 18 '11 at 23:18
  • I did try to clean the project first and make it small. There may have been another way to make it even smaller. Sorry about that. The zip file says 16mb but the actual folder says 49mb which i thought was cool, it made it that small which is nice. – ReArmedHalo Jun 18 '11 at 23:22
  • I downlaoded ok, and believe it or not, it runs great on my iphone simulator! – Nicolas S Jun 18 '11 at 23:32
  • And great in my ipad simulator! – Nicolas S Jun 18 '11 at 23:34
  • WHAT! So could this mean i have a problem with my simulator? – ReArmedHalo Jun 18 '11 at 23:34
  • Ah! I reset the simulator from the iOS Simulator menu and i tried cleaning it and doing a build (using cmd+B) then clicking run. It ran for me too! That is so weird. Wonder if it was my simulator then. I registered as a develoepr but they can't verify my identity so im stuck with simulator till monday when i call them. Thank you for taking a look though. Wondering still, did i set my classes up properly? or are they supposed to be differnet? – ReArmedHalo Jun 18 '11 at 23:39
  • oh i did not see your comment – Nicolas S Jun 18 '11 at 23:42
  • Thank you! I guess that's all i had to do perhaps then Sometimes it turns out to be the simpiles things that we over look right? lol well thank you very much, i'm marking yours as answer. I'll do it an hour because I am leaving were i am now. like after i press enter. Thank you again! – ReArmedHalo Jun 18 '11 at 23:42
1

The line UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); just means that an exception was thrown during the running of your program. This could range from a memory problem, to a simple runtime error. Look in the target debugger console; it will tell you where the error occurred.

Open "iOS Simulator" Menu in the upper left->Reset Content and Settings. Then quit the iOS simulator and Xcode, and then restart your computer. This will get rid of the other instance of the process.

This May work it's work for me...........

Dinesh_
  • 259
  • 1
  • 5
  • 9
0

I also had this error. After spending so much time, I found how to fix it. First of all go the console and see where is the error (mine was related to storyboards and its code) The way I fixed my error was by going in story board. Below the iPhone screen, there will be small yellow button. Right click on it and you will see that is causing error. Delete(x) it if there is yellow error sign.

If this does not fix your error then try to make new project and then replace its blank files with old files of your old project. I had same error in very beginning and by doing this program run without any error.

Other people suggests by restarting your laptop and running it again, reseting the iOS simulator, or changing iOS debugger (however this does not work in latest x code since there is only one debugger)

Hope this helps

mike
  • 313
  • 1
  • 4
  • 14
0

The problem is with your XIB file. This error generally occurs when your finalLabel is incorrectly hooked up or doesn't exist anymore. Check your connections in the Interface Builder once.

Deepak Danduprolu
  • 44,595
  • 12
  • 101
  • 105
  • Okay, i checked, they weren't connected i had that occur in two places. They are now but it still occurs with same thing. Thank you for suggesting that though, without it my app would have not worked anyways – ReArmedHalo Jun 18 '11 at 22:02
  • Are there any warning indicators on any of the connections? – Deepak Danduprolu Jun 18 '11 at 22:13
  • Ok. How are you creating the `FirstViewController` instance? Can you add the code for that? I think you might be creating it like this `[[UIViewController alloc] initWithNibName:@"FirstViewController" bundle:nil];` – Deepak Danduprolu Jun 18 '11 at 22:18
  • I honestly don't have an idea how I did it. I don't think i modified any of it and it just worked. It worked before i tried making it universal but i don't know what i did. – ReArmedHalo Jun 18 '11 at 22:22