asynctask
我在从类文件访问由此填充的数组列表时遇到问题A
。从类文件B
中,我尝试使用 A 一种方法,例如
inStream = new InboxLoader(MainInbox.this,1);
Log.e("JJJ",""+inStream.getMemId().size());
来自不同类文件的方法我在 logcat 中遇到崩溃,说indexoutofbounds error
我正在寻找一种替代方法,以将其与 class
public class InboxLoader { Context ctx;AsyncTask
放在同一个文件中 B
ArrayListmemName,memAvatar,msgBody,msgTime; ArrayList msgId,memId;
InboxLoader(Context context,int id){
this.ctx = context;
this.msgBody = new ArrayList<String>();
this.memAvatar = new ArrayList<String>();
this.memId = new ArrayList<Integer>();
this.memName = new ArrayList<String>();
this.msgTime = new ArrayList<String>();
this.msgId = new ArrayList<Integer>();
new LoadStream().execute(id);
}
public ArrayList<String> getMsgBody(){
return msgBody;
}
public ArrayList<String> getMemAvatar(){
return memAvatar;
}
public ArrayList<Integer> getMemId(){
return memId;
}
public ArrayList<String> getMemName(){
return memName;
}
public ArrayList<Integer> getMsgId(){
return msgId;
}
public ArrayList<String> getMsgTime(){
return msgTime;
}
/*
* STARTS GRABBING DATA FOR THE LISTVIEW
*/
public class LoadStream extends AsyncTask<Integer, Integer, JSONObject> {
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<NameValuePair> params2 = new ArrayList<NameValuePair>();
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 < 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
}
}
}