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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T00:19:05+00:00 2026-06-13T00:19:05+00:00

What is wrong with this code that uses AsyncTask? In particular: – what parameters

  • 0

What is wrong with this code that uses AsyncTask? In particular:
– what parameters do I need to put in fetchSchools
– what parameters do I need to put in doInBackground?

I’ve found lots of “helpful” examples but they all use pseudocode in these parameters and don’t explain what I actually need to put there.

“I get the Eclipse error the method fetchSchools must implement the inherited abstract method AsynchTask…”

I don’t need to pass this anything, I expect it to return a string.

public class fetchSchools extends AsyncTask<Void, Void, String> {

public String doInBackground(String retval) {
       StringBuilder builder = new StringBuilder();
        HttpClient client = new DefaultHttpClient();

        HttpGet httpGet = new HttpGet("http://www.domain/schools.php");
        try 
     {
          HttpResponse response = client.execute(httpGet);
          StatusLine statusLine = response.getStatusLine();
          int statusCode = statusLine.getStatusCode();
          if (statusCode == 200) {
            HttpEntity entity = response.getEntity();
            InputStream content = entity.getContent();
            BufferedReader reader = new BufferedReader(new InputStreamReader(content));
            String
     line;

            int a=0;
            while ((line = reader.readLine()) != null) {
              builder.append(line);
            Log.i(MainActivity.class.getName(), "Reading in: " + a +" : "+ line);
            a++;
            }
          } else {
            Log.e(MainActivity.class.toString(), "Failed to download file");
          }
        } catch (ClientProtocolException e) {
          e.printStackTrace();
        } catch (IOException e)
     {
          e.printStackTrace();
        }

        return builder.toString(); 
}

protected void onPostExecute() {
}

}

  • 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-13T00:19:05+00:00Added an answer on June 13, 2026 at 12:19 am

    you gave doInBackground a string parameter so async task first parameter must be string not void.

    AsyncTask<String , Void, String> {
    

    If you don’t want to pass a parameter, don’t give parameter to doInBackground function.

    check this page for asynctask reference:
    http://developer.android.com/reference/android/os/AsyncTask.html

    First parameter of asynctask goes to doInBackground function, second one goes to onprogressUpdate function, third parameter foes to onpostexecute function.

    I think you want to do this:

     public class fetchSchools extends AsyncTask<Void, Void, String> {
        @Override
        protected String doInBackground(Void... arg0) {
          StringBuilder builder = new StringBuilder();
          HttpClient client = new DefaultHttpClient();
          // ...
    
         return builder.toString();
        }
        protected void onPostExecute(String retval) 
        {
    
        }
      }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm looking at some code that uses PATH_SEPARATOR . I don't think this constant
I've a long version of a program that uses this code and a short
I have this simple piece of code that uses boost::bind: #include <boost/bind.hpp> #include <utility>
I have this piece of code that originally uses the replace function(VBA) to replace
I have this code that uses a template parent class A that has one
Whats wrong with this code? -(void) drawRect:(CGRect) rect { CGContextRef c = UIGraphicsGetCurrentContext(); if
Is there anything wrong with this code or can this be done more efficiently?
what's wrong with this code in Google Chrome r = webkitIndexedDB.open(db_name,1); r.onsuccess = success_callback;
What's wrong with this code?: SolverContext sc = SolverContext.GetContext(); Model m = sc.CreateModel(); m.AddDecision(new
Why is this code correct: try { } catch(ArrayOutOfBoundsException e) {} and this wrong:

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.