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!
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
Jeff Noble900 Points
I'm trying to apply the build a blog reader application to my own blog. I populated my own JSON data here: http://www.evotechmachine.com/api/get_recent_posts/?count=10
The data is organized almost exactly as the teamtreehouse example. I checked to make sure names are the same and they are. The only thing that I thought I would need to change would be this line:
URL blogFeedUrl = new URL("http://www.evotechmachine.com/api/get_recent_posts?count=" + NUMBER_OF_POSTS);
I changed the NUMBER_OF_POSTS member variable to reflect the 10 posts that I wanted. According to the logcat I'm running into a problem here:
int contentLength = connection.getContentLength(); char charArray = new char[contentLength];
Not a big deal, but If someone has an inkling of what I'm doing wrong Id appreciate it.
Ernest GrzybowskiTreehouse Project Reviewer
It's most likely a content length problem. Log the content length and tell me your output.
Log.v("TESTING", contentLength);. If you get -1 there, then that's your problem. Content length is optional to be sent by a server. A lot of dynamic servers (I believe won't set this). Such as some google json outputs you can fetch.
EDIT: Seems you are not the first with this problem. Follow along with this thread and it should help you: https://teamtreehouse.com/forum/problem-in-the-getcontentlength-function?sort=my-posts
Jeff Noble900 Points
I haven't quite solved the problem yet, but I think I know what the problem is. I think there is a limit to the charArray and too much data is being fed into it. I'm looking for a better way to parse the JSON data (maybe I should just watch more of the videos for this topic....)