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 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