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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T01:10:10+00:00 2026-05-31T01:10:10+00:00

hi im expanded a previous question i asked just to make it clearer. i’m

  • 0

hi im expanded a previous question i asked just to make it clearer. i’m trying to get a json feed from a url and then create a list of titles using a list adapter. my json feed consists of a thing called data inside that an array of news and inside that thing called title.

when i run the app it force closes. I’ve been told its because i have a string inside a for loop and no instance of it outside to go in the adapter. i am new to this so any help would be appreciated heres my code

 try{
            // Create a new HTTP Client
            DefaultHttpClient defaultClient = new DefaultHttpClient();
            // Setup the get request
            HttpGet httpGetRequest = new HttpGet("jsonfeed");

            // Execute the request in the client
            HttpResponse httpResponse = defaultClient.execute(httpGetRequest);
            // Grab the response
            BufferedReader reader = new BufferedReader(new InputStreamReader(httpResponse.getEntity().getContent(), "UTF-8"));
            String json = reader.readLine();


            // Instantiate a JSON object from the request response
            JSONObject jsonObject = new JSONObject(json);



            JSONArray jArray = jsonObject.getJSONArray("news");

            String oneObjectsItem1 = null;
            for (int i=0; i < jArray.length(); i++)
            {
                JSONObject oneObject = jArray.getJSONObject(i);
                // Pulling items from the array

                String oneObjectsItem = oneObject.getString("title");



            }


        } catch(Exception e){
            // In your production code handle any errors and catch the individual exceptions
            e.printStackTrace();
        }





        setListAdapter ( new ArrayAdapter<String>(this, R.layout.single_item, oneObjectsItem)); 
        ListView list = getListView();
        list.setTextFilterEnabled(true);
  • 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-31T01:10:11+00:00Added an answer on May 31, 2026 at 1:10 am

    Your error is not clear since we don’t know what you’re doing after you get the JSON, here’s the proper way to get and handle it, and a possible fix for the string itself. Also, please consider accepting answers that you use, like in your question here: How to parse JSON in Android

    Second of all, you’re going over a whole array and creating a new object every time.

    Remove This

    String oneObjectsItem1 = null;
    for (int i=0; i < jArray.length(); i++)
    {
        JSONObject oneObject = jArray.getJSONObject(i);
        // Pulling items from the array
        String oneObjectsItem = oneObject.getString("title");
    }
    

    Use This

    JSONArray jArray = MYJSONOBJECT.getJSONArray("JSONARRAYNAME");
    ArrayList<String> myTitlesFromMyArray = new ArrayList<String>();
    for (int i=0; i < jArray.length(); i++)
    {
        JSONObject oneObject = jArray.getJSONObject(i);
        // TITLE IS IN MY ARRAY I WANT ALL TITLES IN MY LIST OF TITLES
        myTitlesFromMyArray.add(oneObject.getString("title"));
    }
    
    // Iterate through the ENTIRE list and do whatever you want with the items in order
    for (String p: myTitlesFromMyArray)
    {
         // Do something with p
    }
    

    Also, I think your stream for the json string may come back incomplete, to ensure it is complete change it

    Remove This

    String json = reader.readLine();
    

    Use This

    StringBuilder sb = new StringBuilder();
    
    String input = null;
    while ((input = reader.readLine()) != null)
    {
        sb.append(input + "\n");
    }
    String json = input.toString();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to get a variable expanded in a command call. Here's what I
I'm using a Java program to get expanded URLs from short URLs. Given a
Following on from a previous question, ( Previous question ), I can't seem to
I am currently using DevExpress 10.2 within Visual Studio 2010. In a previous question
In linux, when a terminal (like xterm) gets resized to something smaller, then expanded
so I just expanded the glass area of my form into the client area
I'm using addClass() to add .expanded to an element on click. I then don't
The Android NDK has just been significantly expanded to include support for writing android
I have these set of code from a helper: $(document).ready(function(expanded) { var listItems =
My last question expanded, so let's analyse things separately. AND-operater, Intersection? I will give

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.