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 Adapting Data for Display in a List Filling Our String Array and Creating the Adapter

hyunsoo hwang
hyunsoo hwang
3,910 Points

Challenge task 1 of 3

for (int i =0; i<jsonVideos.length(); i++) {
  JSONObject video = jsonData.getJSONObject(i);
  String title = video.getString("title");
  titles[i] = title;

Above is the for loop I wrote for this code challenge but I am getting the below error message.

JavaTester.java:71: getJSONObject(java.lang.String) in org.json.JSONObject cannot be applied to (int)
  JSONObject video = jsonData.getJSONObject(i);
1 error

Can someone help me what I did wrong?

1 Answer

Grant Hosticka
Grant Hosticka
4,172 Points

in the first line of your for loop it should be jsonVideos.getJSONObject(i); instead of jsonData.getJSONObject(i); you are attempting to get data from the wrong source