0

我在我的 android 应用程序中搜索数据并通过控制台进行调试,当我检查控制台时,我看到doInBackground工作正常,但在它没有调用onPostExecute. 不知道是什么原因,有人可以帮忙吗?

   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);
    }
}

这里的日志永远不会执行,请问有什么问题吗?的try作品doInBackground

4

2 回答 2

1

它的onPostExecute(),不是OnPostExecute()。中使用小写字母oonPostExecute()

用这个替换你的代码:

@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如果您尝试覆盖方法,请始终尝试添加注释。这样你就会知道你是否正确地编写了方法签名。

于 2013-09-21T20:30:28.503 回答
1

你的方法是大写的,打破了java约定。调用实际方法onPostExecute()。因为名称不同,您实际上并没有覆盖该方法。这种事情就是@Override注释如此有用的原因——如果你使用它,它会在这里给你一个编译错误。

于 2013-09-21T20:31:32.997 回答