Welcome to the Treehouse Community
The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Varun Nayak
1,634 PointsUnterminated string Exception in Blog Reader project
When i run the app I'm getting an Exception sometimes and otherwise it works fine. I need to keep restarting my app a few times to get the List populated.
Code giving exception:
InputStream inputStream = connection.getInputStream();
Reader reader = new InputStreamReader(inputStream);
int contentLength = connection.getContentLength();
char[] charArray = new char[contentLength];
reader.read(charArray);
String responseData = new String(charArray);
jsonResponse = new JSONObject(responseData);
Exception :
5067-5538/com.example.blogreader.app E/MainListActivity? Exception Caught: org.json.JSONException: Unterminated string at character 6073
After debugging a few times & evaluating the responseData variable I came to know that the JSON response is sometimes mutated with a lot of ?????? 's in the end when returned. Here below is how its returned when I get the error :
{"status":"ok","count":20,"count_total":1702,"pages":86,"posts":[{"id":23268,"url":"http:\/\/blog.teamtreehouse.com\/5-skills-didnt-know-needed","title":"5 Skills You Didn’t Know You Needed","date":"2014-04-14 11:24:27","author":"Ryan Brinks","thumbnail":"http:\/\/blog.teamtreehouse.com\/wp-content\/uploads\/2014\/04\/Flickr-Falcon-Mohammed-Alnaser-3-150x150.jpg"},{"id":23258,"url":"http:\/\/blog.teamtreehouse.com\/create-smoother-animations-transitions-browser","title":"How to Create Smoother Animations and Transitions in the Browser","date":"2014-04-10 15:31:44","author":"Guil Hernandez","thumbnail":null},{"id":23276,"url":"http:\/\/blog.teamtreehouse.com\/hackfests-heart-innovation-invention-creativity","title":"Hackfests Are at the Heart of Creativity and Collaboration \u2014 and Beer Apps","date":"2014-04-10 10:47:23","author":"Kelley King","thumbnail":"http:\/\/blog.teamtreehouse.com\/wp-content\/uploads\/2014\/04\/QuickLeft-Beerfest-Hackfest-West-Falnders-Diebolt-23rd-Studios-Photography-1-150x150.jpg"},{"id":23262,"url":"http:\/\/blog.teamtreehouse.com\/designers-inspiration","title":"For Designers, a Little Inspiration Goes a Long Way","date":"2014-04-09 09:45:25","author":"Kirsten Klahn","thumbnail":"http:\/\/blog.teamtreehouse.com\/wp-content\/uploads\/2014\/04\/Klahn-1-150x150.png"},{"id":23267,"url":"http:\/\/blog.teamtreehouse.com\/flexbox-css-sass-style-guides-html-frameworks-treehouse-show-episode-85","title":"Flexbox, CSS and Sass Style Guides, HTML Frameworks | The Treehouse Show Episode 85","date":"2014-04-08 14:50:58","author":"Jason Seifer","thumbnail":null},{"id":23253,"url":"http:\/\/blog.teamtreehouse.com\/rapidly-prototype-websites","title":"How I Rapidly Prototype Websites","date":"2014-04-08 12:55:59","author":"Nick Pettit","thumbnail":"http:\/\/blog.teamtreehouse.com\/wp-content\/uploads\/2014\/04\/odot-drawing-150x150.png"},{"id":23248,"url":"http:\/\/blog.teamtreehouse.com\/treehouse-helped-find-work-share-story-us","title":"Has Treehouse Helped You Find Work? Share Your Story With Us","date":"2014-04-03 18:43:01","author":"Treehouse","thumbnail":"http:\/\/blog.teamtreehouse.com\/wp-content\/uploads\/2014\/04\/earn-learn4-150x150.jpg"},{"id":23229,"url":"http:\/\/blog.teamtreehouse.com\/common-css-front-end-code-mistakes","title":"How to Evaluate Front-End Code for Inefficiencies","date":"2014-04????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
What does this happen? Why is the JSON response mutated sometimes and on other occasion is working fine?
2 Answers

Ben Jakuben
Treehouse TeacherSorry for your trouble! There is a bug in this code, and the solution is in the Teacher's Notes below the video. Please check it out and it should solve your issue.

Shubham Gupta
3,429 PointsWhere exactly can I find it? I'm having trouble locate the solution in the Teacher's Notes.

Ben Jakuben
Treehouse TeacherHave a look at this old Forum post which contains new code that should work: https://teamtreehouse.com/forum/trying-to-retrieve-data-from-my-own-blog-help
Masum Bergmann
Courses Plus Student 4,129 PointsMasum Bergmann
Courses Plus Student 4,129 PointsHad the exact same issue as Varun, and the Teacher's Notes solution fixed it. Kudos to all contributors! If most (all?) people are affected by this getContentLength() bug, could you update the video lesson for future generations?
Ben Jakuben
Treehouse TeacherBen Jakuben
Treehouse TeacherAbsolutely. I plan on updating the whole course soon, which is the only reason I've waited thus far. (When it first appeared I thought the notes would be sufficient, but now we try to re-record in such instances.)