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 Build a Blog Reader iPhone App Getting Data from the Web Downloading and Parsing JSON Data

Runtime error: 'NSInvalidArgumentException', reason: 'data parameter is nil'

I did everything the same way Amit did yet I get a runtime error.. What's the problem? Thanks

Can you copy/paste the error that you are receiving? It'll be easier to pinpoint the problem.

4 Answers

You are receiving that error because the response that comes from the server is empty and the NSJSONSerialization class cannot work with a nil string.

If you share some of the code you have, especially the part where you call the URL and handle the response, I will be able to help further.

This is my viewDidLoad method, pretty much identical to what's shown in the video...

  • (void)viewDidLoad { [super viewDidLoad];

    NSURL *blogURL = [NSURL URLWithString:@"http://blog.teamtreehouse.com/api/get_recent_summary/"];

    NSData *jsonData = [NSData dataWithContentsOfURL:blogURL];

    NSError *error = nil;

    NSDictionary *dataDictionary = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:&error];

    self.blogPosts = [dataDictionary objectForKey:@"posts"]; }

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'data parameter is nil' this is the error I'm receiving

Oh I'm sorry I just noticed something was wrong with my URL address thanks anyways :)

No problem :)

Have the same problem just like you, but there's more information besides NSInvalidArgumentException, here's the description: 2015-10-19 22:24:52.153 BlogReader[1857:94714] App Transport Security has blocked a cleartext HTTP (http://) resource load since it is insecure. Temporary exceptions can be configured via your app's Info.plist file. 2015-10-19 22:24:52.158 BlogReader[1857:94590] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'data parameter is nil'

How can I solve this problem?