Note that there are some explanatory texts on larger screens.

plurals
  1. POAsynctask wont update array
    primarykey
    data
    text
    <p>I am having a problem accessing the arraylists populated by this <code>asynctask</code> from class file <code>A</code>. From Class file <code>B</code> I try to use A a method such as</p> <p><code>inStream = new InboxLoader(MainInbox.this,1); Log.e("JJJ",""+inStream.getMemId().size());</code> </p> <p>method from a different class file I get a crash in logcat saying <code>indexoutofbounds error</code> I was looking for an alternative to having this <code>AsyncTask</code> in the same file as class <code>B</code> public class InboxLoader { Context ctx; ArrayListmemName,memAvatar,msgBody,msgTime; ArrayList msgId,memId;</p> <pre><code>InboxLoader(Context context,int id){ this.ctx = context; this.msgBody = new ArrayList&lt;String&gt;(); this.memAvatar = new ArrayList&lt;String&gt;(); this.memId = new ArrayList&lt;Integer&gt;(); this.memName = new ArrayList&lt;String&gt;(); this.msgTime = new ArrayList&lt;String&gt;(); this.msgId = new ArrayList&lt;Integer&gt;(); new LoadStream().execute(id); } public ArrayList&lt;String&gt; getMsgBody(){ return msgBody; } public ArrayList&lt;String&gt; getMemAvatar(){ return memAvatar; } public ArrayList&lt;Integer&gt; getMemId(){ return memId; } public ArrayList&lt;String&gt; getMemName(){ return memName; } public ArrayList&lt;Integer&gt; getMsgId(){ return msgId; } public ArrayList&lt;String&gt; getMsgTime(){ return msgTime; } /* * STARTS GRABBING DATA FOR THE LISTVIEW */ public class LoadStream extends AsyncTask&lt;Integer, Integer, JSONObject&gt; { ProgressDialog progressBar; @Override protected void onPreExecute() { progressBar = new ProgressDialog(ctx, ProgressDialog.STYLE_SPINNER); progressBar.setMessage("Generating Inbox...."); progressBar.show(); super.onPreExecute(); } @Override protected JSONObject doInBackground(Integer... params) { List&lt;NameValuePair&gt; params2 = new ArrayList&lt;NameValuePair&gt;(); params2.add(new BasicNameValuePair("memberId", String.valueOf(1))); params2.add(new BasicNameValuePair("type", "get")); JSONObject json = new jsonParser().makeRequest("url", params2); return json; } @Override protected void onPostExecute(JSONObject json) { super.onPostExecute(json); int success = 0; JSONObject jData; JSONArray jObj = null; try{ // successfully received details jObj = json.getJSONArray("details"); // JSON Array success = json.getInt("success"); }catch(Exception e){ e.printStackTrace(); } if(success == 1){ try{ for( int i = 0; i &lt; jObj.length(); i++ ){ //GET OBJECT FROM JSON Array jData = jObj.getJSONObject(i); //ASSIGN VALUES msgId.add(jData.getInt("msg_id")); memAvatar.add(jData.getString("mem_avatar")); memName.add(jData.getString("mem_name")); memId.add(jData.getInt("mem_id")); msgBody.add(jData.getString("msg_body")); msgTime.add(jData.getString("msg_time")); } }catch(Exception e){ Log.e("STREAM FILE PROBLEM", e.getMessage()); } } progressBar.dismiss(); Log.e("STREAM FILE PROBLEM",""+memId.size());//prints 1 } } } </code></pre>
    singulars
    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.
    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