views:

190

answers:

1

UIImageView *one = [[UIImageView alloc]initWithImage:[[UIImage alloc] initWithContentsOfFile:[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"ball1.png"]]] ;

UIImageView *two = [[UIImageView alloc]initWithImage:[[UIImage alloc] initWithContentsOfFile:[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"ball2.png"]]] ;
UIImageView *three = [[UIImageView alloc]initWithImage:[[UIImage alloc] initWithContentsOfFile:[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"ball3.png"]]] ;

arrayBalls = [[NSArray alloc]initWithObjects:one,two,three,nil];

I used the above code for displaying image in the pickerview. But the application is crashing when executing this code.

Anyone please help.

A: 

What errors are you getting, take a look at the stack trace, ect...

Without that information it is hard to diagnose your problem, however it looks like your code is full of leaks. My guess is that you are not following proper memory management techniques and are not releasing things approprately. Also there is an easier way to do what you are trying to do:

UIImageView *one = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"ball1.png"]]
...
NSArray* ballsArray = [NSArray arrayWithObjects:one,two,three,nil];
[one release];
[two release];
[three release];

Make sure you add the images to your project (right click > add > add existing files)

Check out the CS139P lecture on memory management.

W.R.T. your comment: The type of error you are getting happens when you have not properly retained an object and then try to send it a message.

You're code probably looks something like this

@interface SomeObject : NSObject{
   NSString* aString;
}

@implementation SomeObject

-(void)someMethod{
    aString = [NSString stringWithString:@"A String"];
    ...
}
-(void)someOtherMethod{
    [aString isEqualToString:@"A String"];
    ...
}

If you don't understand why this fails, you really need to go back and review how memory management works with the iphone.

Please download and listen to the CS193P Lecture on memory management from iTunes U, it helped me, it will help you.

Ben
I got the following error please help*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[UIImageView isEqualToString:]: unrecognized selector sent to instance 0x4a21df0'
iSharreth