I’m trying to execute a doInBackground AsycTask from a static function, but when I try to enter in the parms for Void, I get a Java error, saying ‘Void’ is not applicable for the Task
‘String, Void, Boolean’
Anyway, here’s my code:
public class RequestHandler extends AsyncTask<URL, Void, Boolean> {
//atributes for Async
private static Context context;
private RequestHandler origin;
// Constructor
public RequestHandler(Context c) {
origin = this;
context = c;
}
public static boolean doLogin(String username, String password) {
String URL = "http://127.0.0.1:1337";
new RequestHandler(context).execute(URL, Void, false); // what do I put here?
}
@Override
protected Boolean doInBackground(URL... params) {
// TODO Auto-generated method stub
URL url = null;
try {
HttpURLConnection urlConnection = null;
try {
urlConnection = (HttpURLConnection) url.openConnection();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
try {
InputStream in = null;
try {
in = new BufferedInputStream(urlConnection.getInputStream());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
readStream(in);
} finally {
}
return false;
}
private String readStream(InputStream is) {
try {
ByteArrayOutputStream bo = new ByteArrayOutputStream();
int i = is.read();
while(i != -1) {
bo.write(i);
i = is.read();
}
return bo.toString();
} catch (IOException e) {
return "";
}
}
}
new RequestHandler(context).execute(URL);protected Boolean doInBackground(String... params) {….}