Note that there are some explanatory texts on larger screens.

plurals
  1. POAsyncTask and JSON, onSuccess doesn't return anything
    primarykey
    data
    text
    <p>I'm here with another question. I post you the code from my AsyncTask function to get values from a JSONObject (webservice). My problem is that I have a List and I fill this list with the data from the json in the onSuccess method, but later, in the onPostExecute method of the AsyncTask, "result" is null.</p> <pre><code>private class getCategories extends AsyncTask&lt;String, Void, List&lt;Category&gt;&gt; { private int num_cat_subcat; // category count @Override protected List&lt;Category&gt; doInBackground(String... arg0) { AsyncHttpClient client = new AsyncHttpClient(); client.get(arg0[0], null, new JsonHttpResponseHandler() { public void onSuccess(JSONObject data) { try { JSONObject response = data.getJSONObject("response"); JSONArray categories = response .getJSONArray("categories"); // elements count num_cat_subcat = categories.length(); for (int i = 0; i &lt; categories.length(); i++) { JSONObject item = (JSONObject) categories .getJSONObject(i); if (item.getString("id").equalsIgnoreCase( "4d4b7105d754a06376d81259")) { JSONArray subcategories = item .getJSONArray("categories"); // Category --&gt; id, name, pluralName, shortName, // icon_prefix, icon_suffix, primary, parentId Category newItem = new Category(item .getString("id"), item .getString("name"), item .getString("pluralName"), item .getString("shortName"), null, null, null); listCategories.add(newItem); newItem = null; if (subcategories.length() &gt; 0) { // Si tiene subcategorias las contamos. num_cat_subcat += subcategories.length(); for (int j = 0; j &lt; subcategories.length(); j++) { JSONObject subitem = (JSONObject) subcategories .getJSONObject(j); Category newSubItem = new Category( subitem.getString("id"), subitem.getString("name"), subitem.getString("pluralName"), subitem.getString("shortName"), null, null, item .getString("id")); listCategories.add(newSubItem); newSubItem = null; } } } } } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } } public void onFailure(Throwable arg0) { } }); return listCategories; } @Override protected void onPostExecute(List&lt;Category&gt; result) { Log.i("result", result.toString()); for (int k = 0; k &lt; result.size(); k++) { ALLOFTHEM += result.get(k).getId(); if (k &lt; result.size() - 1) { ALLOFTHEM += ","; } } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload