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

martin chibwe
martin chibwe
3,901 Points

1.need help working on downloading files from parse.com

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSURL initWithString:relativeToURL:]: nil string parameter'

6 Answers

martin chibwe
martin chibwe
3,901 Points

this is my code

import "imageViewViewController.h"

@interface imageViewViewController ()

@end

@implementation imageViewViewController

  • (void)viewDidLoad { [super viewDidLoad];

//
PFFile *imageFile = [self.message objectForKey:@"file"]; NSURL *imageFileUrl = [[NSURL alloc] initWithString:imageFile.url]; NSData *imageData = [NSData dataWithContentsOfURL:imageFileUrl]; self.imageView.image = [UIImage imageWithData:imageData];

//

}

@end

Stone Preston
Stone Preston
42,016 Points

ok add the following logs to your code to see if your message object actually holds data

 PFFile *imageFile = [self.message objectForKey:@"file"];

NSLog(@"imageFile: %@", imageFile);
NSLog(@"imageFileURL: %@", imageFile.url);

    NSURL *imageFileUrl = [[NSURL alloc] initWithString:imageFile.url];
    NSData *imageData = [NSData dataWithContentsOfURL:imageFileUrl];
    self.imageView.image = [UIImage imageWithData:imageData];

post what comes back in the console. if its nil you have a problem with your message being saved (maybe the url isnt being saved or something)

martin chibwe
martin chibwe
3,901 Points

am getting this

imageFile: (null) 2014-07-20 23:15:39.144 Ribbit[6390:60b] imageFileURL: (null) 2014-07-20 23:15:39.355 Ribbit[6390:60b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSURL initWithString:relativeToURL:]: nil string parameter'

martin chibwe
martin chibwe
3,901 Points

looks like i don't have an image

Stone Preston
Stone Preston
42,016 Points

ok so your image is null. you can do the same style of logs where ever you upload the message. find in your code where you upload the message, and log the file attribute of your message object just before it gets uploaded to parse. if it comes back null something is wrong with your code where you upload the file