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 Build a Blog Reader Android App Getting Data from the Web Parsing Data Returned in JSON Format

Andy Sing
Andy Sing
2,190 Points

data parsing final challenge task 3 of 3

i need the format : book title, a comma, a space, and the number of pages.

example : 'book title 1, 300'.

my code output

Log.i("CodeChallenge", "title" + ", " + "pages");

no compiler errors just "bummer! make sure you write each book to the log exactly as specified in the instructions.

Any help much appreciated have worked many different ways of doing it but with out being able to see how it is coming out can't tell what i'm missing.

Amin Lalji
Amin Lalji
1,350 Points

Your output must look similar to the following in the LogCat Console right?

CodeChallenge title, pages

It's because you are passing String literals instead of variables.

Try removing the quotation marks around the variables... e,g,

Log.i("CodeChallenge", title + ", " + pages);

Hope this helps

3 Answers

Andy Sing
Andy Sing
2,190 Points

I didn't realize it sorry for the trick question I didn't purposely do that but the error was a couple lines above that line. I was saving the number as a string.

Amin Lalji
Amin Lalji
1,350 Points

No Worries - Happens to the best of us :) Feel free to mark my comment above as the best answer if it helped you out.

Ramrakesh Azhagesan
Ramrakesh Azhagesan
7,238 Points

// JSONObject 'jsonData' was loaded from data.jsonJSONArray jsonBooks = jsonData.getJSONArray("books");

String name = jsonData.getString("name");

String publisher = jsonData.getString("publisher");

String language = jsonData.getString("language");

JSONArray jsonBooks = jsonData.getJSONArray("books");

for (int i = 0;i < jsonBooks.length();i++) {

JSONObject jsonBook = jsonBooks.getJSONObject(i);

String title = jsonData.getString("title");

int pages = jsonData.getInt("pages");

Log.i("CodeChallenge",title + ", " + pages); }

I am still getting the same error :(

Thanks in advance