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

Android

NegativeArraySizeException Blog Reader App

I've completed the Blog Reader App tutorial and it worked like a charm. Trying to change the url from the teamtreehouse blog to my own custom link which returns a jsonarray, i've got the exception NegativeArraySizeException: -1. Found out which line of the code got me this exception and it was : char[] charArray = new char[contentLength]; The code is the same as the blog reader app and i believe the problem is getting the contentlength of the connection. After the exception i checked the value of connection.getContentLength() and i got -1 as answer. Got any suggestions?

1 Answer

Solved the fix is bellow.

The api that returns the json must return the following headers: header('Content-Type: application/json; charset=UTF-8'); for json reponse and : header('Content-Encoding: null'); for no gzip encoding.

Cheers.