Reputation: 9157
I have looked at the other questions like this but cannot find help. When I press a button thats supposed to play a sound the app crashes. Here is the debugging console:
The Debugger has exited with status 0.
[Session started at 2011-04-18 18:07:56 +0800.]
GNU gdb 6.3.50-20050815 (Apple version gdb-1515) (Sat Jan 15 08:33:48 UTC 2011)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "x86_64-apple-darwin".sharedlibrary apply-load-rules all Attaching to process 3814.
Program received signal: “EXC_BAD_ACCESS”.
(gdb)
That was the debugger console.
Here is my coding:
AppDelegate.h
#import <UIKit/UIKit.h>
#import <AVFoundation/AVFoundation.h>
@interface MathAppDelegate : NSObject <UIApplicationDelegate> {
AVAudioPlayer* sound;
UIWindow *window;
UINavigationController *navigationController;
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet UINavigationController *navigationController;
-(IBAction)play;
@end
AppDelegate.m
#import "MathAppDelegate.h"
#import "MainMenuViewController.h"
@implementation MathAppDelegate
@synthesize window;
-(IBAction)play {
NSString *path = [[NSBundle mainBundle] pathForResource:@"M1" ofType:@"aif"];
AVAudioPlayer *sound = [[AVAudioPlayer alloc] initWithContentsOfURL: [NSURL fileURLWithPath:path] error:NULL];
sound.delegate = self; ("I get an error here saying 'Local declaration of 'sound' hides instance variable") and ("Class 'MathAppDelegate' does not implement the AVAudioPlayerDelegate' protocol")
[sound play]; ("I get an error here saying 'Local declaration of 'sound' hides instance variable'")
}
I have connected the button to the action in the Interface Builder. What makes me feel like this has messed up is that I had to drag the app delegate object from the mainwindow.xib
to the mainmenuviewcontroller.xib
because that was where I needed to put the button. It still connected though.
Upvotes: 0
Views: 1161
Reputation: 1
Program received signal: “EXC_BAD_ACCESS”.
database1AppDelegate *appDelegate = (database1AppDelegate*)[[UIApplication sharedApplication]delegate];
singleStudent *sStudent = [appDelegate.aryDatabase objectAtIndex:indexPath.row];
cell.textLabel.text = [sStudent strName];
Upvotes: 0
Reputation: 12081
Easiest solution is to have your button actions point to actions available in objects in the same XIB. So you probably want to hook the play action in your main menu controller point to the file's owner, in this case probably your MainMenuViewController
object. I would just move the play action and related code to that file.
The application delegate was an object controller in your MainWindow.xib and configured as a delegate for the window in that same file. Since you moved it to another xib, the delegate of your window now points to a non existing object. This might explain the crash.
Upvotes: 1