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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T16:41:47+00:00 2026-06-04T16:41:47+00:00

I have only one httpclient in my 1st activity which is used in all

  • 0

I have only one httpclient in my 1st activity which is used in all other activities.Because I am using PHP Sessions.

In my 1st Activity I have a listview which takes 4-5 secs to load items
(which will be done by a connection to the server), and in the same activity I have a search field…which on button click takes me to a searchActivity where using same httpclient search results will be loaded in a different listview.
My problem is during the 4-5 sec load time in the 1st activity if I try to search something, my app crashes saying:

Invalid use of SingleClientConnManager: connection still allocated.

Make sure to release the connection before allocating another one.

java.lang.IllegalStateException: No wrapped connection.

and eventually a null pointer exception later

I think as I am using the same httpclient in the searchActivity before completing the 1st Activity is creating this error (correct me if am wrong)

so if my assumption is right how can i release this connection in the intent where i am moving to searchAvtivity from 1st activity??

Thank you

CODE:

    try {
        HttpPost httppost = new HttpPost(
                SignUpActivity.url+"/feed/fetchfeed");
        httppost.setHeader("X_REQUESTED_WITH", "xmlhttprequest");
        httppost.setHeader("MOBILE_DATA_REQUESTED", "mobileHttpRequest");
        HttpResponse response = SignUpActivity.httpclient.execute(httppost);

        Log.d("response", "" + response);
        HttpEntity entity = response.getEntity();

        Log.d("entity", "" + entity);
        is = entity.getContent();

        Log.d("is", "" + is);

        try {
            BufferedReader reader = new BufferedReader(
                    new InputStreamReader(is, "iso-8859-1"), 8);
            sb = new StringBuilder();
            sb.append(reader.readLine() + "\n");

            Log.d("sb", "" + sb);
            String line = "0";
            while ((line = reader.readLine()) != null) {
                sb.append(line + "\n");
            }
            is.close();
            result = sb.toString();
            Log.d("result", result);
        } catch (Exception e) {
            Log.e("error3", "Error in http connection" + e.toString());
        }

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

    try {
        Log.d("JArray", "entered try");
        JArray = new JSONArray(result);
        feed_products_list = new ArrayList<Product>();
        Log.d("JArray", "try last line");
    } catch (JSONException e) {
        Log.d("JArray", "in catch");
        e.printStackTrace();
    }

    JSONObject jsonObj;
    JSONObject jsonObjStore;
    JSONObject jsonObjUser;

    for (int i = 0; i < JArray.length(); i++) {
        try {
            Log.d("jsonObj",
                    "entered try" + " " + i + " " + JArray.length());
            jsonObj = JArray.getJSONObject(i);
            jsonObjUser = jsonObj.getJSONObject("user");
        } catch (Exception e) {
            Log.d("jsonObj", "in catch");
            continue;
        }

        try {
            Log.d("feed_products_list", "entered try");
            Log.d("type of action", jsonObj.getString("action"));
            if (jsonObj.getString("action").equals("entry")) {
                Log.d("if block", "entered block 'entry'");

                jsonObjStore = jsonObj.getJSONObject("store");
                Log.d("store", jsonObjStore.getString("name"));

                feed_products_list.add(new Product(jsonObj.getInt("id"),
                        jsonObj.getString("action"), jsonObj
                                .getString("image"), jsonObj
                                .getString("product_name"), jsonObj
                                .getString("reported_price_formated"),
                        jsonObjStore.getString("name"), jsonObjStore
                                .getString("area"), jsonObjStore
                                .getString("city"), jsonObj
                                .getString("mrp"), jsonObjUser
                                .getString("name"), jsonObj
                                .getLong("reported_timestamp"), jsonObj
                                .getInt("discount"), jsonObjStore
                                .getDouble("lat"), jsonObjStore
                                .getDouble("lng")));

                Log.d("store id", jsonObjStore.getString("id"));
                Log.d("feed_products_list product: ",
                        feed_products_list.get(i).lat + "   "
                                + feed_products_list.get(i).lng);

            } else if (jsonObj.getString("action").equals("contest")) {
                Log.d("if block", "entered block 'contest'");
                feed_products_list.add(new Product(jsonObj.getInt("id"),
                        jsonObj.getString("action"), jsonObjUser
                                .getString("image"), jsonObj
                                .getString("product_name"), jsonObj
                                .getString("city"), jsonObjUser
                                .getString("name"), jsonObj
                                .getLong("reported_timestamp")));

                Log.d("feed_products_list",
                        feed_products_list.get(i).productName);

            }

        } catch (JSONException e) {
            e.printStackTrace();
        }
    }
    m = 1;
}

I added this:

                try {
                    is.close();
            Intent intent = new Intent(FeedListViewActivity.this,
                            SearchActivity.class);
                    startActivity(intent);
                    Log.d("onClick", search_string);
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }

but i got the same error

  • 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-04T16:41:48+00:00Added an answer on June 4, 2026 at 4:41 pm

    Connection are automatically closed if you close the InputStream‘s you get from httpclient. Check your code and make sure you are closing them properly.

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

Sidebar

Related Questions

So I have a dynamic number of jobs which all have only one build
In my app, I have only one Activity which hosts several fragments . The
In my application I have only one activity and I am using ViewAnimator for
I made shoot em up like game.But I have only one ememy which fallows
I m able to get values using JPA when i have only mapped one
I'm currently coding a product which will have only one database but will host
I used to think that an assembly could have only one main() method until
the pages have only one variable which changes, and each page only holds one
I wrote a VB.NET Windows Service, which works fine. I have only one issue
I tried to read a text file which have only one line. File size

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.