Note that there are some explanatory texts on larger screens.

plurals
  1. POAsyncTask return null
    text
    copied!<p>I'm working on app that enables me to load users from php mysql and when I select on of them it opens a new activity to display the name of user and button to delete it. the problem is when I run the app, AllUsersActivity dosen't return the users. It displays an empty page here is the code of the method LoadAllUsers, there was an "else " to move to another avtivity to create user if there was not any user. but I removed it because I want it to display users and delete them without adding. After I removed the add part it returned to me null, although the connection is working right and it retrived the data from the DB in the logcat. can anyone help me with it please</p> <pre><code>/** * Background Async Task to Load all users by making HTTP Request * */ class LoadAllUsers extends AsyncTask&lt;String, String, String&gt; { /** * Before starting background thread Show Progress Dialog * */ @Override protected void onPreExecute() { super.onPreExecute(); pDialog = new ProgressDialog(AllUsersActivity.this); pDialog.setMessage("Loading users. Please wait..."); pDialog.setIndeterminate(false); pDialog.setCancelable(false); pDialog.show(); } /** * getting All users from url * */ protected String doInBackground(String... args) { // Building Parameters List&lt;NameValuePair&gt; params = new ArrayList&lt;NameValuePair&gt;(); // getting JSON string from URL JSONObject json = jParser.makeHttpRequest(url_all_users, "GET", params); // Check your log cat for JSON reponse Log.d("All users: ", json.toString()); try { // Checking for SUCCESS TAG int success = json.getInt(TAG_SUCCESS); if (success == 1) { // user found // Getting Array of user user = json.getJSONArray(TAG_USER); // looping through All users for (int i = 0; i &lt; user.length(); i++) { JSONObject c = user.getJSONObject(i); // Storing each json item in variable String U_mail = c.getString(TAG_UMAIL); String Name = c.getString(TAG_NAME); // creating new HashMap HashMap&lt;String, String&gt; map = new HashMap&lt;String, String&gt;(); // adding each child node to HashMap key =&gt; value map.put(TAG_UMAIL, U_mail); map.put(TAG_NAME, Name); // adding HashList to ArrayList usersList.add(map); } } } catch (JSONException e) { e.printStackTrace(); } return null; } /** * After completing background task Dismiss the progress dialog * **/ protected void onPostExecute(String file_url) { // dismiss the dialog after getting all users pDialog.dismiss(); // updating UI from Background Thread runOnUiThread(new Runnable() { public void run() { /** * Updating parsed JSON data into ListView * */ ListAdapter adapter = new SimpleAdapter( AllUsersActivity.this, usersList, R.layout.list_item, new String[] { TAG_UMAIL, TAG_NAME}, new int[] { R.id.um, R.id.name }); // updating listview setListAdapter(adapter); } }); </code></pre> <p>here is the logcat</p> <pre><code>04-23 09:22:36.814: W/System.err(916): org.json.JSONException: No value for users 04-23 09:22:36.814: W/System.err(916): at org.json.JSONObject.get(JSONObject.java:354) 04-23 09:22:36.814: W/System.err(916): at org.json.JSONObject.getJSONArray(JSONObject.java:544) 04-23 09:22:36.824: W/System.err(916): at com.example.androidhive.AllUsersActivity$LoadAllUsers.doInBackground(AllUsersActivity.java:140) 04-23 09:22:36.824: W/System.err(916): at com.example.androidhive.AllUsersActivity$LoadAllUsers.doInBackground(AllUsersActivity.java:1) 04-23 09:22:36.824: W/System.err(916): at android.os.AsyncTask$2.call(AsyncTask.java:287) 04-23 09:22:36.865: W/System.err(916): at java.util.concurrent.FutureTask.run(FutureTask.java:234) 04-23 09:22:36.924: W/System.err(916): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080) 04-23 09:22:36.924: W/System.err(916): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor .java:573) </code></pre>
 

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