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() {
}
}