2013-09-21 62 views
0

我有一個數據搜索我的android應用程序和調試通過控制檯,當我檢查控制檯時,我看到doInBackground工作正常,但它沒有調用onPostExecute後。我不知道是因爲什麼,有人可以幫忙嗎?OnPostExecute不會調用doInBackground後成功

protected List<Recipe> doInBackground(Void... params) { 
     try { 
      List<Recipe> recipes=RecipeService.getRecipes(context,"a"); 
      if(recipes != null) android.util.Log.i(TAG,"encontrados"); 
      return recipes; 
     } catch (java.io.IOException e) { 
      android.util.Log.e(TAG,e.getMessage(),e); 
      android.util.Log.i(TAG,"ta akiiiiii"); 
      com.android.utils.AndroidUtils.AlertDialog(context,R.string.name_io); 
     }finally{ 
      progresso.dismiss(); 
     } 
     return null; 
    } 


//Update a view 


protected void OnPostExecute(List<Recipe> recipes) { 
    android.util.Log.i(TAG,"are here"); 
    for (Recipe recipe : recipes) { 
     android.util.Log.i(TAG,"Carro: "+recipe.name); 
    } 
} 

日誌在這裏永遠不會執行,請有一些錯誤? trydoInBackground的作品。

回答

1

onPostExecute()而不是OnPostExecute()。在onPostExecute()中使用小寫字母o

這種替換代碼:

@Override 
protected void onPostExecute(List<Recipe> recipes) { 
    android.util.Log.i(TAG,"are here"); 
    for (Recipe recipe : recipes) { 
     android.util.Log.i(TAG,"Carro: "+recipe.name); 
    } 
} 

總是嘗試添加@Override註釋,如果你想覆蓋的方法。這樣你就可以知道你是否正確地寫了方法簽名。

1

你的方法是大寫,打破了Java約定。實際的方法稱爲onPostExecute()。由於名稱不同,因此實際上並未覆蓋該方法。這種事情就是爲什麼@Override註釋非常有用 - 如果你使用它,它會給你一個編譯錯誤。

相關問題