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.

Android Build a Blog Reader Android App Getting Data from the Web Parsing Data Returned in JSON Format

Error in JSONObject code challenge seems unrelated to actual Java code being used

I'm on the third step of the code challenge which prompts me to do the following:

"Finally, write a 'for' loop that loops through 'jsonBooks'. In each step of the loop, use 'getJSONObject(int index)' to get a JSONObject from the array. Then use the 'Log.i()' method (with "CodeChallenge" as the tag) to write the book title, a comma, a space, and the number of pages. Ex. output: 'Book title 1, 300'."

This is my code block...specifically looking at where the for loop begins

// JSONObject 'jsonData' was loaded from data.json
String name = jsonData.getString("name");
String publisher = jsonData.getString("publisher");
String language = jsonData.getString("language");
JSONArray jasonBooks = jsonData.getJSONArray("books");
for (int i = 0; i <jsonBooks.length(); i++) {
  JSONObject jsonBook = jsonBooks.getJSONObject(i);
    String name = jsonBook.getString("name");
  String name =jsonBook.getString("pages");
  Log.v(TAG, name + ", " + pages); 

I would not be surprised if there were compiler errors in the code, but the preview mode shows errors that seem to be relating what appears to be unrelated java

JavaTester.java:141: error: illegal start of expression
  private static void pass() {
  ^
JavaTester.java:141: error: illegal start of expression
  private static void pass() {
          ^
JavaTester.java:141: error: ';' expected
  private static void pass() {
                ^
JavaTester.java:141: error: ';' expected
  private static void pass() {
                            ^
JavaTester.java:145: error: illegal start of expression
  private static void fail(String hint) {
  ^
JavaTester.java:145: error: illegal start of expression
  private static void fail(String hint) {
          ^
JavaTester.java:145: error: ';' expected
  private static void fail(String hint) {
                ^
JavaTester.java:145: error: ')' expected
  private static void fail(String hint) {
                                 ^
JavaTester.java:145: error: illegal start of expression
  private static void fail(String hint) {
                                      ^
JavaTester.java:145: error: ';' expected
  private static void fail(String hint) {
                                       ^
10 errors

I may be missing something, but any help would be appreciated as I can't see how it relates to my code.

Thanks

2 Answers

Harry James
Harry James
14,780 Points

Them errors are in fact completely unrelated. I opened the Code Challenge up for myself and, without entering anything into the Code Challenge, I get the same errors as you.

I'm not sure if this has always been like this or if it's just a bug right now. I seem to also get a Communication Problem when using the Preview button.

Left it a while and came back to the code challenge...the first few steps went smoothly again but its throwing the same errors again on the third step. Would be great if this could be sorted asap Treehouse.

Harry James
Harry James
14,780 Points

I will tag Ben Jakuben here to take a look at this issue for you :)