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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T10:09:40+00:00 2026-06-07T10:09:40+00:00

I am trying to call a method I have written. It compiles except for

  • 0

I am trying to call a method I have written. It compiles except for one line…

public class http extends Activity {

httpMethod();            //will not compile



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

    try {
        // Add your data
        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);

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

        String test = "hello";

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

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

I’m not the best java guy, but I would think calling the method like so would get a response. “Hello” is not displayed however…

How do I properly call the method?

  • 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-07T10:09:41+00:00Added an answer on June 7, 2026 at 10:09 am

    EDIT: Just to leave no-one in any doubt, this answer only addresses why you’re getting a compile-time error. It does not address what you should be doing in which thread and at what time in Android.

    Personally I would recommend that you put Android down for the moment, learn Java in a simpler environment (e.g. console apps) and then, when you’re comfortable with the language, revisit Android and learn all the requirements of Android development – which are obviously much more than just the language.


    You’re trying to call a method as a statement directly within your class. You can’t do that – it has to be part of a constructor, initializer block, other method, or static initializer. For example:

    // TODO: Rename this class to comply with Java naming conventions
    public class http extends Activity {
        // Constructor is able to call the method... or you could call
        // it from any other method, e.g. onCreate, onResume
        public http() {
            httpMethod();
        }
    
        public void httpMethod() {
            ....
        }
    }
    

    Note that I’ve only given this example to show you a valid Java class. It doesn’t mean you should actually be calling the method from your constructor.

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

Sidebar

Related Questions

I am trying to call a method I have written in C# from VBScript.
I have a method which I am trying to call dynamically. That method has
I am trying to use a string to call a method? Suppose I have
I'm trying to call a method from another class with a simple button in
I'm trying to call a boolean method in another class and Eclipse is reporting
I'm trying to call method from .jar But when I want to declare array
Im trying to call a method that will add or subtract 1 from a
I am trying to call a method that requires some parameters based on previous
I am currently trying to call a method in the aspx.cs inside of my
Possible Duplicate: javascript object, access variable property name? I'm trying to call a method

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.