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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T08:05:17+00:00 2026-06-07T08:05:17+00:00

I am trying to contact an API and get the response. As part of

  • 0

I am trying to contact an API and get the response. As part of my debugging I want to insure that the response is being recorded, it should be an xml response.

Here’s what I have:

public class http extends Activity {

public void httpMethod(){
    HttpClient httpclient = new DefaultHttpClient();
    HttpPost httppost = new HttpPost("http://site.com/api/");

    try {
        // Add your data
        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
        nameValuePairs.add(new BasicNameValuePair("apikey", "0d4e122d20"));

        nameValuePairs.add(new BasicNameValuePair("ip", "65.82.126.103"));
        httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

        // Execute HTTP Post Request
        HttpResponse response = httpclient.execute(httppost);

    } catch (ClientProtocolException e) {
        // TODO Auto-generated catch block
    } catch (IOException e) {
        // TODO Auto-generated catch block
    }

   TextView myTextView = (TextView) findViewById(R.id.myTextView);
   myTextView.setText(response);
}
}

I’m trying to see the response that I get, however the variable response in the line

myTextView.setText(response)

is throwing an error:

response cannot be resolved to a variable

is response not truly a variable of the type httpresponse? what’s going on here…?

  • 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-07T08:05:20+00:00Added an answer on June 7, 2026 at 8:05 am

    Scope of the response variable is inside try block only. Two ways to resolve this:

    1) Move these statements right after HttpResponse response = httpclient.execute(httppost);

     TextView myTextView = (TextView) findViewById(R.id.myTextView);
       myTextView.setText(response);
    

    2) Define HttpResponse response out side the try.

    EDIT: As WindyB specified when you define outside the try block make sure null check to avoid NullPointerException.

    Read this link

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

Sidebar

Related Questions

I'm trying to parse XML feed that I get via Google Contacts API with
I am trying to get user album by using GRAPH API with function facebook.request(contact.getFacebook_id()+/albums)
I am trying to get contact name, email and phone from google contact api
im trying to parse the XML returned by Google contacts API i made some
Hi I am trying to share contact (vcard) through sms/mms gateway, should i encode
Hi all I am trying to get contact information from the contact database using
Im trying to get all Leads / Contact / Accounts from the database. So
I am trying to be an ABRecordRef that represents the contact info of a
I'm trying to do some test with the Google Contact API V3 (https://developers.google.com/google-apps/contacts/v3/). I'm
I'm trying to interface with the Google Contact API, and in order to update

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.