Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS

Crystal Ball App - Error

So, I am working on the Crystal Ball app and I'm at the animation stage. When I try to run my app, it gives me the following error:


2013-07-06 18:57:22.215 CrystalBall[15489:c07] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<ViewController 0x8987150> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key back.' *** First throw call stack: (0x1c92012 0x10cfe7e 0x1d1afb1 0xb7be41 0xafd5f8 0xafd0e7 0xb27b58 0x231019 0x10e3663 0x1c8d45a 0x22fb1c 0xf47e7 0xf4dc8 0xf4ff8 0xf5232 0x443d5 0x4476f 0x44905 0x4d917 0x1196c 0x1294b 0x23cb5 0x24beb 0x16698 0x1beddf9 0x1bedad0 0x1c07bf5 0x1c07962 0x1c38bb6 0x1c37f44 0x1c37e1b 0x1217a 0x13ffc 0x279d 0x26c5) libc++abi.dylib: terminate called throwing an exception

(lldb)

I didn't see this error before adding in the code. Has anyone faced this issue/know what to do?

My code is the same as the one in the video, so I'm not sure what is going wrong. I can supply my code if needed.

Thank you!

1 Answer

Yes, If you can supply the code, that would be great. I'm currently working through that exact project--in fact I'm almost done with it--and I haven't experienced that error just yet. I've gotten to the "Shake things up" portion--and I'm loving it, and I have a lot of great idea on how to improve the app as well. But any rate, I did run into an error when adding new code to the project through the various phases. These was no real error, just a self terminating condition that didn't allow the emulator to run the project. But that was solved by rebooting Eclipse.

But lets have a look see at the code you have written so far.

Oh, how can I reboot Eclipse?

Here is my ViewController.m file code (sorry about the formatting):


#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController;
@synthesize predictionLabel;
@synthesize predictionArray;
@synthesize imageView;

    // Release any cached data, images, etc that aren't in use.


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

    UIImage *image = [UIImage imageNamed:@"background.png"];
    self.imageView =[[UIImageView alloc] initWithImage:image];
    [self.view insertSubview:self.imageView atIndex:0];


    self.imageView.animationImages = [[NSArray alloc] initWithObjects:
        [UIImage imageNamed: @"cb1.png"],
        [UIImage imageNamed: @"cb2.png"],
        [UIImage imageNamed: @"cb3.png"],
        [UIImage imageNamed: @"cb4.png"],
        [UIImage imageNamed: @"cb5.png"],
        [UIImage imageNamed: @"cb6.png"],
        [UIImage imageNamed: @"cb7.png"],
        [UIImage imageNamed: @"cb8.png"],
        [UIImage imageNamed: @"cb9.png"],
        [UIImage imageNamed: @"cb10.png"],
        [UIImage imageNamed: @"cb11.png"],
        [UIImage imageNamed: @"cb12.png"],
        [UIImage imageNamed: @"cb13.png"],
        [UIImage imageNamed: @"cb14.png"],
        [UIImage imageNamed: @"cb15.png"],
        [UIImage imageNamed: @"cb16.png"],
        [UIImage imageNamed: @"cb17.png"],
        [UIImage imageNamed: @"cb18.png"],
        [UIImage imageNamed: @"cb19.png"],
        [UIImage imageNamed: @"cb20.png"],
        [UIImage imageNamed: @"cb21.png"],
        [UIImage imageNamed: @"cb22.png"],
        [UIImage imageNamed: @"cb23.png"],
        [UIImage imageNamed: @"cb24.png"],
        nil];

    self.imageView.animationDuration = 1.0;
    self.imageView.animationRepeatCount = 1;

    self.predictionArray = [[NSArray alloc] initWithObjects:
                                @"It is certain",
                                @"It is decidedly so",
                                @"All signs say 'Yes'",
                                @"The stars are not aligned",
                                @"My reply is no",
                                @"It is doubtful",
                                @"Better not tell you now",
                                @"Concentrate and ask again",
                                @"Unable to answer now",
                                @"Too soon to tell",
                                @"Maybe",
                                @"It appears likely",
                                @"It is highly probable",
                                @"Maybe if you had better luck",
                                @"Only if you BELIEVE",
                                @"Not in your dreams",   nil];

}

    // Dispose of any resources that can be recreated.

- (void) makePrediction {
    NSUInteger index = arc4random_uniform(self.predictionArray.count);
    self.predictionLabel.text = [self.predictionArray objectAtIndex:(index)];

    [self.imageView startAnimating];
}

- (BOOL) canBecomeFirstResponder {
    return YES;
}

- (void) motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event {
    self.predictionLabel.text = @"";

}
- (void) motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event {
    if (motion == UIEventSubtypeMotionShake) {

        [self makePrediction];

    }
}
- (void) motionCancelled:(UIEventSubtype)motion withEvent:(UIEvent *)event {
    NSLog(@"Motion Cancelled");
}

- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    self.predictionLabel.text = @"";

}

- (void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {

   [self makePrediction];
}

@end
Amit Bijlani
Amit Bijlani
Treehouse Guest Teacher

It's possible there's something wrong in your StoryBoard and how you have wired your Outlets or Actions. I would say delete and re-create them

Thank you so much! I deleted and re-created the outlets and now my app is running again!

However, my animation is not working (before I had the error and after I fixed it). I still can see the prediction pop up, but the animation cycle does not run. I added this code to see if the animation was running:

if (self.imageView.isAnimating) { NSLog(@"animation running"); }

This logged the statement "animation running," but I can't see the animation.

Could you let me know what is wrong? I have copied my ViewController.m file above.

Amit Bijlani
Amit Bijlani
Treehouse Guest Teacher

Could it be that you added a background image using the storyboard as well as in your code within the viewDidLoad method? You should have either one of them, otherwise one will hide the other.

I deleted the background image from within the viewDidLoad method and it solved my problem! Thank you so much!