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 trialNancy Melucci
Courses Plus Student 36,158 PointsjsonShows array - stumped
for (int i = 0; i < jsonShows.length(); i++)
{
JSONObject shows = jsonShows.getJSONObject(i);
String title = jsonShows.getString("title");
int season = jsonShows.getInt("season");
int episode = jsonShows.getInt("episode");
}
I don't really understand what else to do here to make the object and instantiate the array. I just know that I could spend 3 days on this and I don't have a lot of time. I'm off from my day job and I can't afford to be stopped dead in building this app because I can't figure out what to do here. I'm following the array structure and trying to use the operation in the last video as a guide. Any hints as to what I should add or remove to get past this first Challenge Task would be appreciated. In two weeks I won't be able to work on this anymore. I can't spend two weeks (as apparently some fellow Treehouse denizens have) trying to dope this out. Moving on in the meantime. Thanks again.
Nancy M.
5 Answers
Evan Demaris
64,262 PointsHi Nancy,
I definitely don't recommend spending 2 weeks - or, frankly, even 2 days - on ANY Challenge. The forums are a good place to get help when you're stuck!
// Create the JSONArray object called jsonShows;
// Use getJSONArray method of the JSONObject called jsonData (loaded from data.json);
// Use the "shows" array within jsonData as the argument for getJSONArray;
JSONArray jsonShows = jsonData.getJSONArray("shows");
// Part 2 of the Challenge asks you to make the 'for' loop through jsonShows;
for (int i = 0; i < jsonShows.length(); i++){
// Then get a JSONObject with each loop;
JSONObject jObject = jsonShows.getJSONObject(i);
// Lastly, use the Log.i method to write the show title;
Log.i("CodeChallenge", jObject.getString("title"));
}
Please let me know if you have any other questions!
Nancy Melucci
Courses Plus Student 36,158 PointsAh it looks like I was doing too much, which is programming is often not a good thing.
When I re-read my post I thought "Whiner!". Sorry. I really really enjoy programming, and app development - and I love Treehouse but I am a busy college prof (looking to make a career change and still no where near ready to "quit my day job" skills-wise.) I am trying to exploit the lull in my spring break to do a lot of tutorials here. Once the semester starts I won't be able to pick it up but every now and then.
Thanks very much for your patient help. Now back to my other problems with this (my layout is messed up and though the data is coming in - I see it in the console when the app runs - the temperature isn't showing like Ben's is.) Onward!
Evan Demaris
64,262 PointsDon't worry about coming across as a whiner, everyone has 'down' moments while learning to code - especially if you're studying for a career change.
When having problems with convincing your app to work, one trick you can use it to download the project files and compare Ben's code to yours. Or if you can't find where your project is different, you can always just replace your project with his project!
Nancy Melucci
Courses Plus Student 36,158 PointsAh ah great minds! I just figured that strategy out. And I fixed a major mistake that was making the app crash AND brought back the temperature. It is running and showing weather info.
The layout still looks like crap. But I remember him saying we could fool around with this.
Part of the problem I am sure is that I opened it as a Blank Activity and so I am forever stuck with a Floating Action Button. Minor issue I guess.
Thanks for your encouragement. Happy New Year.
N
Evan Demaris
64,262 PointsHappy to help!
When you say Floating Action Button, do you mean the ActionBar? If so, you can change that in the res>values>styles.xml by updating the last section of the apptheme from whatever it is currently (probably DarkActionBar?) to NoActionBar.
If you don't mean the ActionBar, the FloatingActionButton View can just be deleted from the XML to get rid of it.
Nancy Melucci
Courses Plus Student 36,158 PointsSheepishly I must admit I cannot find it. It's definitely a button (it's got a little envelope on it...default email.) I am using a very recent version of Studio where it is part of the app when you start up. I deleted the code from MainActivity but I cannot find the XML I don't want to hurl tons of XML at you. If there are some likely candidates, I can send. Working on it. N
Nancy Melucci
Courses Plus Student 36,158 PointsHey responding helped me figure it out. I found the code and killed the FAB. Thanks again! N
Evan Demaris
64,262 PointsYou're welcome, good job!