Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7681779
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T18:25:09+00:00 2026-05-31T18:25:09+00:00

Hi I keep getting this error, I’m trying to get tweets from twitter via

  • 0

Hi I keep getting this error, I’m trying to get tweets from twitter via JSON and cant seem to get rid of this on the “arr”. Would I have to do a different for loop? I did try this but it keeps returning the same error.

 public ArrayList<Tweet> getTweets(String searchTerm, int page) {
      String searchUrl = 
            "http://search.twitter.com/search.json?q=@" 
            + searchTerm + "&rpp=100&page=" + page;

      ArrayList<Tweet> tweets = 
            new ArrayList<Tweet>();

      HttpClient client = new  DefaultHttpClient();
      HttpGet get = new HttpGet(searchUrl);

      ResponseHandler<String> responseHandler = 
            new BasicResponseHandler();

      String responseBody = null;
      try {
        responseBody = client.execute(get, responseHandler);
      } catch(Exception ex) {
        ex.printStackTrace();
      }

      JSONObject jsonObject = null;
      JSONParser parser = new JSONParser();

      try {
        Object obj = parser.parse(responseBody);
        jsonObject=(JSONObject)obj;
      }catch(Exception ex){
        Log.v("TEST","Exception: " + ex.getMessage());
      }

      JSONArray<Object> arr = null;

      try {
        Object j = jsonObject.get("results");
        arr = (JSONArray)j;
      } catch(Exception ex){
        Log.v("TEST","Exception: " + ex.getMessage());
      }

      for(Object t : arr) {
        Tweet tweet = new Tweet(
          ((JSONObject)t).get("from_user").toString(),
          ((JSONObject)t).get("text").toString(),
          ((JSONObject)t).get("profile_image_url").toString()
        );
        tweets.add(tweet);
      }

      return tweets;
    }

Please help!!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T18:25:10+00:00Added an answer on May 31, 2026 at 6:25 pm

    As the exception says, you can only iterate with the for each loop on instances of java.lang.Iterable. JSONArray is not one of them.

    Use the “classic” for loop :

    for(int i = 0; i < arr.length(); i++) {
       JSONObject t = (JSONObject) arr.get(i);
       Tweet tweet = new Tweet(
         t.get("from_user").toString(),
         t.get("text").toString(),
         t.get("profile_image_url").toString()
       );
       tweets.add(tweet);
     }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I keep getting this error when trying to delete a record from my table.
Keep getting this error after inserting a subdatasheet into a query and trying to
I keep getting this error when trying to do a git pull or a
I keep getting this error after cloning a repository from the AndEngine project.. The
I keep getting this error mesage when trying to add a breakpoint in gdb.
I keep getting this error when trying to configure the upload directory with Apache
I keep getting this error message from the code below. What am I doing
I keep getting this error message when trying to write to the Event log
I keep getting this error when trying to view my channels controller. uninitialized constant
I keep getting this error from my code and I have no idea what

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.