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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T08:09:29+00:00 2026-06-16T08:09:29+00:00

I have a program to download JSON Strings from a server. Things were working

  • 0

I have a program to download JSON Strings from a server. Things were working fine up until recently, when I try to call

jsonReader.execute(getUrl).get();

Where jsonReader is an AsyncTask to download JSON Strings and getUrl is the URL to execute. This method never gets executed, the weird thing is, it works on my phone.

Here is my code

Method which calls json string reader

private PointOfInterest getPointWithID(int id) {

    String getUrl;
    JSONReader jsonReader = new JSONReader();
    try {
        Log.d(TAG,"Trying to get ID: " + id);
        getUrl = url + String.valueOf(id);
        Log.d(TAG,"Trying to get json from: " + id); <-- Last Log line to get printed when run on emulator
        jsonReader.execute(getUrl).get();
    } catch (Exception e) {
        e.printStackTrace();
    }

    String jsonString = jsonReader.returnJSONString();
    Log.d(TAG,"Downloaded: " + jsonString);
    //System.out.println("JSON: " + jsonString);

    JSONResponse jsonResponse = JSONResponse.convertJSONToResponse(jsonString);
    //System.out.println("JSON RESPONSE " + jsonResponse);


    return jsonResponse.getPointofInterest();
}

jsonReader

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.params.BasicHttpParams;
import org.json.JSONException;
import org.json.JSONObject;

import android.os.AsyncTask;
import android.util.Log;

/**
 * Read JSON Strings
 * @author Tom
 *
 */
public class JSONReader extends AsyncTask <String, Void, String> {

    String result;
    DefaultHttpClient  httpclient = new DefaultHttpClient(new BasicHttpParams());
    StringBuilder sb = new StringBuilder();
    String TAG = "JSONReader";

    // constructor
    public JSONReader() {
        result = "";
    }

    @Override
    protected String doInBackground(String... url) {

        Log.d(TAG, "Executing " + url); <--Does not get printed when run on emulator 

        HttpPost httppost = new HttpPost(url[0]);
        // Depends on your web service
        httppost.setHeader("Content-type", "application/json");

        try {
            HttpResponse response = httpclient.execute(httppost);

            HttpEntity entity = response.getEntity();

            InputStream inputStream = entity.getContent();

            // json is UTF-8 by default i believe
            BufferedReader reader = null;

            reader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"), 8);

            String line = null;
            while ((line = reader.readLine()) != null)
            {
                sb.append(line + "\n");
            }
        }catch(Exception e){

            e.printStackTrace();
        }
        return result = sb.toString();
    }

    public String returnJSONString(){

        return result;
    }

}

I have tried restarting adb, making new AVD’s but nothing seems to work, my only option is testing on my phone however, this is not desirable as I am developing for api 17. Thanks for your help !

  • 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-16T08:09:30+00:00Added an answer on June 16, 2026 at 8:09 am

    There are a few threading rules that must be followed for this class to work properly:

    The AsyncTask class must be loaded on the UI thread. This is done automatically as of JELLY_BEAN.

    The task instance must be created on the UI thread.

    execute(Params…) must be invoked on the UI thread.
    Do not call onPreExecute(), onPostExecute(Result), doInBackground(Params…), onProgressUpdate(Progress…) manually.

    The task can be executed only once (an exception will be thrown if a second execution is attempted.)

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

Sidebar

Related Questions

I have a program that gets a JSON from the server using getJSON and
i have a program which i can download a video file from a server
Well, I have this program, the download option is working fine. I can access
I have a program that downloads PCM data from a Web Server, which it
I have a downloader program that download pages from internet . the encoding of
I have a VBA program to download attachments from a Mail Item. I launch
I use a ruby program to download data from staging server and to populate
I'm writing a program which must download documents from google docs. I have downloaded
My iOS program download [A.sqlite3] file in server. My iOS have already [b.sqlite3] file
I try to type a single program have (client) and (multi-client server) to send

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.