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 Android Lists and Adapters (2015) Updating the Data Model From JSONArray to a Java Array

Soumitra Mehrotra
Soumitra Mehrotra
337 Points

Why didn't we directly used hours[i].setSummary(jsonHour.getString("summary")); ???

In the video , first we wrote Hour[] hours=new Hour[data.length()]; Then,we have declared Hour hour=new hour() ; for each iteration and then, we wrote hour.setSummary(jsonHour.getString("summary")); At last we did hours[i]=hour;

why is that we could have used directly??I tried but the apps stops??

1 Answer

You could use hours[i] but first you need to create an object to hold the data so you should write it like this hours[i] = new Hour(); then you could use hours[i].setSummary(jsonHour.getString("summary")); and at the end its the same it's just reference

Soumitra Mehrotra
Soumitra Mehrotra
337 Points

Oh ok thanx. I got confused.!!