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 trialAlistair Ruff
3,272 PointsError 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
14,780 PointsThem 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.
Alistair Ruff
3,272 PointsLeft 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
14,780 PointsI will tag Ben Jakuben here to take a look at this issue for you :)