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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T08:36:27+00:00 2026-05-24T08:36:27+00:00

I have an activity class that gets a JSON string by making a query.

  • 0

I have an activity class that gets a JSON string by making a query. I parsed the string into a ArrayList(HashMap(String, String)). I am passing this to a ListView. The problem I am facing is while displaying the elements of the ArrayList only the last element in the list is shown in the UI. i.e. if there are 3 elements in the list, the third element is shown thrice

This is my Function. The “buglist” view has a ListView in it and R.id.text1/2/3 are basically TextViews.

public class GetBugs extends ListActivity {

public static final String BASE_URL = "http://172.19.194.89:3000";
 public static String response_string="default message";
private static ArrayList<HashMap<String,String>> buglist;


/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  buglist = new ArrayList<HashMap<String,String>>();
  setContentView(R.layout.bugslist);
}

@Override
public void onStart(){
  super.onStart();

  // Send a HTTP GET Request to get bug details
  String bugs=RestClient.getData("http://172.19.194.89:3000/bug");
  //String count=RestClient.getData("http://172.19.194.89:3000/count");
  Log.i("DEBUG","BUGS LIST:"+bugs);
  parseBugs(bugs);
  ListAdapter adapter = new SimpleAdapter(this, buglist, R.layout.bugrow, 
            new String[] {"summary","platform","product"},
            new int[] {R.id.text1,R.id.text2, R.id.text3});

  setListAdapter(adapter);


 }

 public void parseBugs(String bugstring){
  try {
    JSONObject jobject = new JSONObject(bugstring);
    JSONArray bugdetails = jobject.getJSONArray("bugs");
    int i=0;
    HashMap<String, String> item = new HashMap<String, String>();
    String item_val;
    JSONObject e = new JSONObject();
    while(i<bugdetails.length()){
        e=bugdetails.getJSONObject(i);
        item_val = e.getString("summary");
        item.put("summary", item_val);
        item_val = e.getString("platform");
        item.put("platform", item_val);
        item_val = e.getString("product");
        item.put("product", item_val);
        buglist.add(i, item);
        i++;
    }
    Log.i("INFO", "The HashMap Array is populated");

} catch (JSONException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}
 }

I can provide the views also if needed. When i debug the code, I was able to see that the bugslist variable is set correctly, so i assume the problem might be with the way its accessing the variable in the view.

These are the views

1.bugslist.xml

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">  

<ListView
android:id="@id/android:list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="2"
android:drawSelectorOnTop="false">
</ListView>
<TextView android:id="@id/android:empty"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="No data">
</TextView>

</LinearLayout>

2.bugrow.xml

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">  

<TextView
android:id="@+id/text1"
android:textSize="16sp"
android:textStyle="bold"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
</TextView>

<TextView android:id="@+id/text2"
android:textSize="12sp"
android:textStyle="bold"
android:layout_width="wrap_content"
android:layout_height="fill_parent">
</TextView>

<TextView android:id="@+id/text3"
android:typeface="sans"
android:textSize="14sp"
android:textStyle="italic"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</TextView>

</LinearLayout>

Thanks
Sreenath

  • 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-24T08:36:28+00:00Added an answer on May 24, 2026 at 8:36 am

    Because you add the same object three times.
    you should create a new hashmap instance very time.

    public void parseBugs(String bugstring){
      try {
        JSONObject jobject = new JSONObject(bugstring);
        JSONArray bugdetails = jobject.getJSONArray("bugs");
        int i=0;
        String item_val;
        JSONObject e = new JSONObject();
        while(i<bugdetails.length()){
            HashMap<String, String> item = new HashMap<String, String>();
            e=bugdetails.getJSONObject(i);
            item_val = e.getString("summary");
            item.put("summary", item_val);
            item_val = e.getString("platform");
            item.put("platform", item_val);
            item_val = e.getString("product");
            item.put("product", item_val);
            buglist.add(i, item);
            i++;
        }
        Log.i("INFO", "The HashMap Array is populated");
    
    } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this activity that class a Login class inside an onclick event. My
I have an app that hits a REST service, gets some json and then
I have a public class FriendMaps extends MapActivity that gets called from a menu
In my activity, I have an AutoCompleteTextView that gets its contents from my custom
I have class that extends 'IntentService' - this class occasionally receives data from a
I have an Android Activity that uses a class that I developed that extends
I have a problem that, I have a serializable class which sets and gets
I have a list of objects called Activity: class Activity { public Date activityDate;
I have 3 classes in my example: Class A, the main activity. Class A
I have an activity that has a TabHost containing a set of TabSpecs each

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.