したがって、この AsyncTask getValids をメソッドで呼び出します。パート I はログに記録されますが、パート II は記録されません
Log.v("","entered main & 0 part I");
String[] str_validsI = new getValids().execute("main").get();
Log.v("","entered main & 0 part II");
それでも、最初の Log.v は印刷されず、他の関数は呼び出されません
protected String[] doInBackground(String... cat){
Log.v("We are getting a HTTP Response","1");
また、PreExecute IS が呼び出されます
protected void onPreExecute(){
Log.v("","We're in pre execture");
//this is the last function that is printed
}
これは getValids クラスです。doInBackground は呼び出されず、何も返されません。なぜですか?
何が間違っているのか、なぜ呼び出されないのか、誰にもわかりますか?
public class getValids extends AsyncTask<String,Void,String[]> {
public List<String> retd = new ArrayList<String>();
private InputStream is = null;
//public List<String> getValids(String cat)
protected String[] doInBackground(String... cat){
Log.v("We are getting a HTTP Response","1");
String base_url = "http://universitytimes.ie/mobile/";
String url = null;
List<String> list = Arrays.asList("aaaa".split("\\s*"));
Log.v("We are getting a HTTP Response","2");
if (cat.equals("main")){
url = base_url;
}else{
url = base_url+cat;
}
try {
// default HTTPClient
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpGet httpGet = new HttpGet(url);
HttpResponse httpResponse = httpClient.execute(httpGet);
Log.v("We are getting a HTTP Response","The status " + httpResponse.getStatusLine().getStatusCode());
HttpEntity httpEntity = httpResponse.getEntity();
is = httpEntity.getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(is,"UTF-8"));
StringBuilder sb = new StringBuilder();
String line = "";
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
is.close();
String str_valids = sb.toString();
list = Arrays.asList(str_valids.split("\\s*,\\s*"));
}catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return list.toArray(new String[list.size()]);
} //end do in bg
public void setResult(List<String> in){
Log.v("We are getting a HTTP Response","1");
retd = in;
}
public List<String> getResult(){
return retd;
}
protected void onPreExecute(){
Log.v("","We're in pre execture");
}
protected void onProgessUpdate(){}
protected void onPostExecute(List<String> result){
setResult(result);
}
}