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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T06:22:06+00:00 2026-06-16T06:22:06+00:00

I have an AsynTask which retrieve data from a web service and with this

  • 0

I have an AsynTask which retrieve data from a web service and with this data to be viewed on the UI. So, in my MainActivity, I have a textView.

This is the data I received from the webservice:

{"name":"ezio","country":"italy"}{"name":"fufu","country":"tutu"}{"name":"chikaka","country":"aceVentura"}

The problem is, I do not know how to set the textView with the value of ‘result’ from the ClientConnection class. When I run the application, the textView is empty.

public class ClientConnection extends AsyncTask {

public static final String URL = "http://192.168.0.15/test.php";

static JSONObject jObj = null;
public static String result = "";

@Override
protected String doInBackground(Void... voids) {

    // public JSONObject connect(){
    try{
        HttpClient httpClient = new DefaultHttpClient();
        HttpGet httpGet = new HttpGet(URL);
        HttpResponse response = httpClient.execute(httpGet);

        int statusCode = response.getStatusLine().getStatusCode();
        if (statusCode != HttpStatus.SC_OK) {
            Log.e("HTTPStatus error:","Status not okay");
        }

        InputStream in = response.getEntity().getContent();
        BufferedReader reader =  new BufferedReader(new InputStreamReader(in, "iso-8859-1"), 8);
        StringBuilder str = new StringBuilder();
        String line = null;
        while((line = reader.readLine()) != null){
            str.append(line + "\n");
        }
        in.close();
        result = str.toString();

        JSONObject jsonObject = convertToJson(result);

        // jsonObject.get()
        //result = jsonObject.getString("name");
        //JSONArray google = jsonObject.getJSONArray("");


    } catch (Exception e) {
        //Toast toast = Toast.makeText(null, e.getMessage(), Toast.LENGTH_LONG);
        Log.e("Error","don't know what exception though");
    }

    return result;
}

private JSONObject convertToJson(String test){

    JSONArray clients = new JSONArray();

    try{
        jObj = new JSONObject(test);

    }catch (JSONException e){
        Log.e("JSON Parser", "Error parsing data" + e.toString());
    }

    return jObj;
}

public String getResult(){
        return result;
    }
    public JSONObject getjObj(){
        return jObj;
    }
}

And this is the Main Activity

public class MyActivity extends Activity {
    /**
     * Called when the activity is first created.
     */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        final TextView textView = (TextView) findViewById(R.id.textViewTest);
        ListView listView = (ListView) findViewById(R.id.listView);
        Button buttonConnect = (Button) findViewById(R.id.buttonConnect);

        final ClientJSONParsingActivity clientJSONParsingActivity = new ClientJSONParsingActivity();

        buttonConnect.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                new ClientConnection().execute();

                textView.setText(new ClientConnection().getResult());

            }
        });
    }
}

Thank you 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-16T06:22:07+00:00Added an answer on June 16, 2026 at 6:22 am

    You should update textview in your asynctask. onPostExecute() method runs on UI thread

     protected void onPostExecute(String result) {
          textView.setText(result);
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Service downloading data every second from a web server (This Service
I have an Activity that retrieves data from a web service. This data is
I have android AsynTask method that call the Web Service which returns the List<>
I have an Android app which uses a service to continuously update a textview
this is the current state/situation: I have an Activity which binds a Service which
I have created an app which retrieves the data from a url using xml
I have an AsyncTask which retrieves data from a server and then needs to
I have an app in android which retrieve a picture from http page.I'm asking
I have an Android application which retrieves information from the web using an AsyncTask
I have a spinner which is populated from the database. This in turn is

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.