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 7915761
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T14:34:01+00:00 2026-06-03T14:34:01+00:00

I want to build an android-based twitter feed reader app. I have problems in

  • 0

I want to build an android-based twitter feed reader app. I have problems in parsing the json response. Here is my code:

`public class HttpClientActivity extends Activity {

class Tweet{
    public String username;
    public String message;
}

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

static ArrayList<String> resultRow;

@Override
public void onCreate(Bundle savedInstanceState) {
    StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
    StrictMode.setThreadPolicy(policy);

    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    public class Getdata {

public String getInternetData() throws Exception{

    String data = null;

    try {
        URI website = new URI("http://search.twitter.com/search.json?q=blue%20angels&rpp=5&include_entities=true&result_type=mixed&include_rts=5");
        HttpClient client = new DefaultHttpClient();
        HttpGet request = new HttpGet();
        request.setURI(website);
        HttpResponse response = client.execute(request);
        HttpEntity entity = response.getEntity();
        data = EntityUtils.toString(entity);

    }catch(Exception e){
        Log.e("log_tag", "Error in http connection: " +e.toString());
    }

    return data;
    }

    }

    Getdata getdata = new Getdata();
    String returned = null;
    try {
        returned = getdata.getInternetData();
    } catch (Exception e) {
        e.printStackTrace();
    }


    try{
        JSONArray jarray = new JSONArray(returned);
        for(int i=0; i<jarray.length(); i++){
            JSONObject jo = jarray.getJSONObject(i);
            Tweet tt = new Tweet();
            tt.username = jo.getString("from_user");
            tt.message = jo.getString("text");
            tweets.add(tt);
        }
    }
    catch(JSONException e){
        Log.e("log_tag", "Error parsing data: "+e.toString());
    }

    ListView lv = (ListView) findViewById(R.id.listView1);



    class FancyAdapter extends ArrayAdapter<Tweet> {

        public FancyAdapter() {
            super(HttpClientActivity.this, android.R.layout.simple_list_item_1, tweets);
        }

        public View getView(int position, View convertView, ViewGroup parent){
            ViewHolder holder;
            if(convertView == null){
                LayoutInflater inflater = getLayoutInflater();
                convertView = inflater.inflate(R.layout.listitem, null);
                holder = new ViewHolder(convertView);
                convertView.setTag(holder);
            }
            else
            {
                holder = (ViewHolder)convertView.getTag();
            }
            holder.populatefrom(tweets.get(position));
            return(convertView);
        }


        class ViewHolder {
            public TextView username = null;
            public TextView message = null;

            ViewHolder(View listitem){
                username = (TextView)listitem.findViewById(R.id.username);
                message = (TextView)listitem.findViewById(R.id.message);
            }

            void populatefrom(Tweet t){
                username.setText(t.username);
                message.setText(t.message);
            }
        }
    }

    FancyAdapter ar = new FancyAdapter();
    lv.setAdapter(ar);

}

}

Now i got the msg:

org.json.JSONException: Value of type java.lang.String cannot be
converted to JSONArray

I dont know hot to fix it:

try{
            JSONArray jarray = new JSONArray(returned);
            for(int i=0; i<jarray.length(); i++){
                JSONObject jo = jarray.getJSONObject(i);
                Tweet tt = new Tweet();
                tt.username = jo.getString("from_user");
                tt.message = jo.getString("text");
                tweets.add(tt);
            }
      }
  • 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-06-03T14:34:02+00:00Added an answer on June 3, 2026 at 2:34 pm

    To get a JSONArray you first need a JSONObject:

    http://www.json.org/

    Example JSON Object with array in it:

     String returned = "{ "myArray" : [item1, item2] }"
    
     JSONObject jsonObj = new JSONObject(returned);
    
     JSONArray jarray = jsonObj.getJSONArray("myArray");
    

    Using your example of : http://search.twitter.com/search.json?q=blue%20angels&rpp=5&include_entities=true&result_type=mixed&include_rts=5

     JSONObject jsonObj = new JSONObject(returned);
     JSONArray jarray = jsonObj.getJSONArray("results");
     JSONObject firstResult = jarray.getJSONObject(0); // loop if you want more
     String username = firstResult.getString("from_user");
     String message = firstResults.getString("text");
    

    If you put it through a formatter like this : http://jsonformatter.curiousconcept.com/ its 100000x easier to read

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some NDK based C++ code that needs to build an android bitmap
I want to build an notepad-style application on android that will have syntax highlighting.
I want to integrate Facebook with my Birthday App, so I started https://developers.facebook.com/docs/mobile/android/build/ working
I have build my very first application to Android and I want now to
I'm planning to build an Android App. based on Augmented Reality . I googled
I want to build a PDF reader/viewer that could be used in my Android
I am planing to build an android app, which will have user posted content
I'm planning to build an Android App. based on Augmented Reality . I googled
I have a project and I want to build it for Android. I want
i want to build a android dictionary app using trie. so m i new

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.