Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Mockup & CodeGen, iPhone & iPad
($9.99)

Make your own iPhone apps
and run them live!
(free)

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 10-20-2009, 11:06 PM   #1 (permalink)
Registered Member
 
Join Date: Oct 2009
Posts: 30
Default app freezes when I press button

Hi I am new to programing, and I have been working on an app that plays a random sound when you press a button. No I'm not making another fart app.
The program does not show any errors, However when the app loads, on both the sim and device, when i press the button it just stays blue and freezes. Any help would be very appreciated. here is the code Im using:


- (IBAction)playSoundid)sender
{
int randomNumber = arc4random() % 25 + 1;

NSString *tmpFileName = [[NSString alloc] initWithFormat:@"sound%d", randomNumber];
NSString *fileName = [[NSBundle mainBundle] pathForResource:tmpFileName ofType:@"aif"];

SystemSoundID soundID;
AudioServicesCreateSystemSoundID((CFURLRef)[NSURL fileURLWithPath:fileName], &soundID);
AudioServicesPlaySystemSound (soundID);

[tmpFileName release];
[fileName release];
}


I know its probably something simple with my code but once again I am new to programing and am still coming to terms with this language.
Karts9 is offline   Reply With Quote
Old 10-20-2009, 11:40 PM   #2 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,129
Default

Don't release fileName. The only time you should release is if you did an alloc, copy, new, or retain.
__________________
BriTer Ideas LLC - Code review, consulting, development. PM for pricing.

SlickShopper 2 | Free NSLog utility | Leave a PayPal donation.

Are you a newbie? Things you should read:
BrianSlick is online now   Reply With Quote
Old 10-20-2009, 11:57 PM   #3 (permalink)
Registered Member
 
Join Date: Oct 2009
Posts: 30
Default

ok i got rid of the filename release, but I think i have another issue somewhere. I noticed a messeage that said:" __TERMINATING_DUE TO_UNCAUGHT_EXEPCTION__"

Any Idea on what I need to do to fix this??
Karts9 is offline   Reply With Quote
Old 10-20-2009, 11:58 PM   #4 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,129
Default

No idea without code. Add some log messages to figure out where it is dying.
__________________
BriTer Ideas LLC - Code review, consulting, development. PM for pricing.

SlickShopper 2 | Free NSLog utility | Leave a PayPal donation.

Are you a newbie? Things you should read:
BrianSlick is online now   Reply With Quote
Old 10-21-2009, 12:07 AM   #5 (permalink)
Registered Member
 
Join Date: Oct 2009
Posts: 30
Default

Does This help?
Code:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSURL initFileURLWithPath:]: nil string parameter'
could it have something to do with this? This is the main.m file
Code:
#import <UIKit/UIKit.h>

int main(int argc, char *argv[]) {
    
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
    int retVal = UIApplicationMain(argc, argv, nil, nil);
    [pool release];
    return retVal;
}
Karts9 is offline   Reply With Quote
Old 10-21-2009, 12:11 AM   #6 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,129
Default

Nope. The important part is right here in your error message:
Code:
 -[NSURL initFileURLWithPath:]: nil string parameter'
Whenever you are given a method name, figure out where you are doing that. The 'nil string parameter' parts means that the string you are using for the path is actually empty. You need to fix that.
__________________
BriTer Ideas LLC - Code review, consulting, development. PM for pricing.

SlickShopper 2 | Free NSLog utility | Leave a PayPal donation.

Are you a newbie? Things you should read:
BrianSlick is online now   Reply With Quote
Old 10-21-2009, 12:26 AM   #7 (permalink)
Registered Member
 
Join Date: Oct 2009
Posts: 30
Default

Oh man I can't believe what the issue was, it was this part here:
Code:
NSString *tmpFileName = [[NSString alloc] initWithFormat:@"sound%d", randomNumber];
My files start with a Capital 'S' for sound and I had put a lower case 's' in the code, it's working now. Thanks for your help.
Karts9 is offline   Reply With Quote
Reply

Bookmarks

Tags
button, freezing, sound

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 241
18 members and 223 guests
ADY, AragornSG, BrianSlick, Dani77, Dattee, dre, glenn_sayers, HemiMG, JasonR, karlam963, nobre84, prchn4christ, Rudy, spiderguy84, themathminister, tomtom100, viniciusdamone, vvenkatachallam
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,884
Threads: 89,229
Posts: 380,763
Top Poster: BrianSlick (7,129)
Welcome to our newest member, karlam963
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 02:19 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0