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

  • SEARCH
  • Home
  • 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 6837473
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:28:53+00:00 2026-05-26T23:28:53+00:00

I am trying to make an app that parses data from Twitter using JSON

  • 0

I am trying to make an app that parses data from Twitter using JSON and get the live twitter feed, I was successfully able to log the data into the logcat, but somehow I am unable to display the same in the ListView, the last news feed is showing up in the ListView but the rest of feeds are gone. I add them in an Arraylist before using an ArrayAdapter to do so.What is wrong with my code, am I parsing the JSONArray and JSONObject correctly or is there any conversion that I am missing?

public class readingtwitterfeedsActivity extends ListActivity {

    @Override
   public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
   // setContentView(R.layout.main);
    String readTwitterFeed = readTwitterFeed();
    try {
        JSONArray jsonArray = new JSONArray(readTwitterFeed);
        Log.i(readingtwitterfeedsActivity.class.getName(),
                "Number of entries " + jsonArray.length());
        for (int i = 0; i < jsonArray.length(); i++) {
            JSONObject jsonObject = jsonArray.getJSONObject(i);
            Log.i(readingtwitterfeedsActivity.class.getName(),   jsonObject.getString("text"));
            List<String> al=new ArrayList<String>();
            al.add(jsonArray.getJSONObject(i).getString("text"));
            ArrayAdapter<String> adapter=new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, al);
            setListAdapter(adapter);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

  public String readTwitterFeed() {
    StringBuilder builder = new StringBuilder();
    HttpClient client = new DefaultHttpClient();
    HttpGet httpGet = new HttpGet(
            "http://twitter.com/statuses/user_timeline/bbcnews.json");
    try {
        HttpResponse response = client.execute(httpGet);
        StatusLine statusLine = response.getStatusLine();
        int statusCode = statusLine.getStatusCode();
        if (statusCode == 200) {
            HttpEntity entity = response.getEntity();
            InputStream content = entity.getContent();
            BufferedReader reader = new BufferedReader(
                    new InputStreamReader(content));
            String line;
            while ((line = reader.readLine()) != null) {
                builder.append(line);
            }
        } else {
            Log.e(readingtwitterfeedsActivity.class.toString(), "Failed to download file");
        }
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return builder.toString();
}
}
  • 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-26T23:28:54+00:00Added an answer on May 26, 2026 at 11:28 pm

    Just initializing the string array before the for loop and set adapter after completion of for loop..

    Try this, replace in your code.

    List<String> al=new ArrayList<String>();
    for (int i = 0; i < jsonArray.length(); i++) {
                JSONObject jsonObject = jsonArray.getJSONObject(i);
                Log.i(readingtwitterfeedsActivity.class.getName(),   jsonObject.getString("text"));
    
                al.add(jsonArray.getJSONObject(i).getString("text"));
    
            }
     ArrayAdapter<String> adapter=new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, al);
                setListAdapter(adapter);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to make an app that will pass data between two servers
Im trying to make an app that converts distance/area/volume using spinners as a unit
I'm trying to make an app that can take images from a directory on
I'm trying to make a console app that would monitor some process and restart
I'm trying to make a simple app that sits on the Mac OSX menu
I am trying to make a web app in Dashcode that uses a range
I'm trying to make my app publish to all my friend's walls. From what
I am trying to make an app that opens android market page of selected
I am trying to make an iPhone-app that does the Monte Carlo simulation on
I'm trying to make an app that will respond to your command when inserted.

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.