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

Can't get titles to show in LogCat

Follwed the exact instructions, but for some reason I still can't get the titles to show in LogCat, any help would be great. Snippet of code is below.

     ***JSONArray jsonPosts = jsonResponse.getJSONArray("posts");
                for (int i = 0; i < jsonPosts.length(); i++) {
                    JSONObject jsonPost = jsonPosts.getJSONObject(i);
                    String title = jsonPost.getString("title");
                    Log.v(TAG, "Post " + i + ": " + title);***

2 Answers

You are missing closing curly brace for the for loop '}' in the above code. May be that's the problem...

It should be placed at the end of the 'for' loop...

JSONArray jsonPosts = jsonResponse.getJSONArray("posts");
                for (int i = 0; i < jsonPosts.length(); i++) {
                    JSONObject jsonPost = jsonPosts.getJSONObject(i);
                    String title = jsonPost.getString("title");
                    Log.v(TAG, "Post " + i + ": " + title);

                 }                                // You were missing this curly brace


            ``` 
Hope it helps...

Try adding a breakpoint at the for line to see if jsonPosts.length() has a value (perhaps add its value in a Toast ). If it doesn't, then the loop will exit without executing.

Then you can step through the code to see what happens, if anything, when it reaches your Log.v statement.

Hope this helps.

Steve.