Thread 1: signal SIGABRT error in main

0

Got this error message in the main function. Am new to debugging this kind of error in Xcode 5, so would appreciate your suggestions about how to approach this kind of error.

Thanks in advance.

Here is the code:

Main:

#import <UIKit/UIKit.h>

#import "BullsEyeAppDelegate.h"

int main(int argc, char * argv[])
{
    @autoreleasepool {
        return UIApplicationMain(argc, argv, nil, NSStringFromClass([BullsEyeAppDelegate class])); //Thread 1: signal SIGABRT
    }
}

BullsEyeViewController.h

#import <UIKit/UIKit.h>

@interface BullsEyeViewController : UIViewController

@property (nonatomic, weak) IBOutlet UISlider *slider;
@property (nonatomic, weak) IBOutlet UILabel *targetLabel;
@property (nonatomic, weak) IBOutlet UILabel *scoreLabel;
@property (nonatomic, weak) IBOutlet UILabel *roundLabel;

-(IBAction)showAlert;
-(IBAction)sliderMoved:(UISlider *)slider;



@end

BullsEyeViewController.m

#import "BullsEyeViewController.h"

@interface BullsEyeViewController ()

@end

@implementation BullsEyeViewController
{
    int _currentValue;
    int _targetValue;
    int _score;
    int _round;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    [self startNewRound];
    [self updateLabels];
}

-(void)startNewRound
{
    _targetValue = 1 + arc4random_uniform(100);
    _currentValue = 50;
    self.slider.value = _currentValue;
    [self updateLabels];
}

-(void)updateLabels
{
    self.targetLabel.text = [NSString stringWithFormat:@"%d", _targetValue];
    // Convert the int into a string so that it will fit in the label as an outlet
    self.scoreLabel.text = [NSString stringWithFormat:@"%d", _score];
    self.roundLabel.text = [NSString stringWithFormat:@"%d", _round];

}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(IBAction)showAlert
{
    int difference = abs(_currentValue - _targetValue);
    int points = 100 - difference;
    _score += points;

    NSString *message = [NSString stringWithFormat:@"You scored %d points", points];

    UIAlertView *alertView = [[UIAlertView alloc]
    initWithTitle:@"Hello World"
          message:message
         delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles: nil];

    [alertView show];

    [self startNewRound];
    [self updateLabels];
}

-(IBAction)sliderMoved:(UISlider *)slider
{
    _currentValue = lroundf(slider.value);
}

@end

Error Trace:

2013-11-19 19:59:12.299 BullsEye[13764:70b] -[UILabel intValue]: unrecognized selector sent to instance 0x8a7ef20
2013-11-19 19:59:12.351 BullsEye[13764:70b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UILabel intValue]: unrecognized selector sent to instance 0x8a7ef20'
*** First throw call stack:
(
    0   CoreFoundation                      0x0173a5e4 __exceptionPreprocess + 180
    1   libobjc.A.dylib                     0x014bd8b6 objc_exception_throw + 44
    2   CoreFoundation                      0x017d7903 -[NSObject(NSObject) doesNotRecognizeSelector:] + 275
    3   CoreFoundation                      0x0172a90b ___forwarding___ + 1019
    4   CoreFoundation                      0x0172a4ee _CF_forwarding_prep_0 + 14
    5   Foundation                          0x0117d737 _NSSetIntValueForKeyInIvar + 46
    6   Foundation                          0x010eada3 _NSSetUsingKeyValueSetter + 256
    7   Foundation                          0x010ea253 -[NSObject(NSKeyValueCoding) setValue:forKey:] + 267
    8   Foundation                          0x0114c70a -[NSObject(NSKeyValueCoding) setValue:forKeyPath:] + 412
    9   UIKit                               0x004cda15 -[UIRuntimeOutletConnection connect] + 106
    10  libobjc.A.dylib                     0x014cf7d2 -[NSObject performSelector:] + 62
    11  CoreFoundation                      0x01735b6a -[NSArray makeObjectsPerformSelector:] + 314
    12  UIKit                               0x004cc56e -[UINib instantiateWithOwner:options:] + 1417
    13  UIKit                               0x0033e605 -[UIViewController _loadViewFromNibNamed:bundle:] + 280
    14  UIKit                               0x0033edad -[UIViewController loadView] + 302
    15  UIKit                               0x0033f0ae -[UIViewController loadViewIfRequired] + 78
    16  UIKit                               0x0033f5b4 -[UIViewController view] + 35
    17  UIKit                               0x002679fd -[UIWindow addRootViewControllerViewIfPossible] + 66
    18  UIKit                               0x00267d97 -[UIWindow _setHidden:forced:] + 312
    19  UIKit                               0x0026802d -[UIWindow _orderFrontWithoutMakingKey] + 49
    20  UIKit                               0x0027289a -[UIWindow makeKeyAndVisible] + 65
    21  UIKit                               0x00225cd0 -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] + 1851
    22  UIKit                               0x0022a3a8 -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 824
    23  UIKit                               0x0023e87c -[UIApplication handleEvent:withNewEvent:] + 3447
    24  UIKit                               0x0023ede9 -[UIApplication sendEvent:] + 85
    25  UIKit                               0x0022c025 _UIApplicationHandleEvent + 736
    26  GraphicsServices                    0x036e12f6 _PurpleEventCallback + 776
    27  GraphicsServices                    0x036e0e01 PurpleEventCallback + 46
    28  CoreFoundation                      0x016b5d65 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 53
    29  CoreFoundation                      0x016b5a9b __CFRunLoopDoSource1 + 523
    30  CoreFoundation                      0x016e077c __CFRunLoopRun + 2156
    31  CoreFoundation                      0x016dfac3 CFRunLoopRunSpecific + 467
    32  CoreFoundation                      0x016df8db CFRunLoopRunInMode + 123
    33  UIKit                               0x00229add -[UIApplication _run] + 840
    34  UIKit                               0x0022bd3b UIApplicationMain + 1225
    35  BullsEye                            0x0000219d main + 141
    36  libdyld.dylib                       0x01d7870d start + 1
    37  ???                                 0x00000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb) 
ios
xcode
debugging
asked on Stack Overflow Nov 20, 2013 by pdenlinger • edited Nov 20, 2013 by pdenlinger

1 Answer

0

These 2 lines reveal your error in the error trace:

2013-11-19 19:59:12.299 BullsEye[13764:70b] -[UILabel intValue]: unrecognized selector sent to instance 0x8a7ef20
2013-11-19 19:59:12.351 BullsEye[13764:70b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UILabel intValue]: unrecognized selector sent to instance 0x8a7ef20'

It appears you error isn't caused by the code you posted but where ever you have:

[UILabel intValue];

Wherever you are using the above code, you are trying to get the integer value of a UILabel, when you should be trying to get the integer value of the text property of the UILabel.

So, assuming the name of your label is "myLabel:"

[myLabel.text intValue];
answered on Stack Overflow Nov 20, 2013 by jhilgert00

User contributions licensed under CC BY-SA 3.0