这个 AsyncTask 代码有什么问题,它阻止它返回数组进度......我在注释行上得到“进度无法解析为变量”。
public class FetchProgress extends AsyncTask<OpportunityActivity, Void, ArrayList<Progress>> {
private OpportunityActivity opportunityActivity;
@Override
protected ArrayList<Progress> doInBackground(OpportunityActivity... activity) {
opportunityActivity = activity[0];
String readFeed = readFeed();
// this JSON feed is delivered correctly
try {
JSONObject json = new JSONObject(readFeed);
JSONObject jsonObject = new JSONObject(json.optString("ShowProgress"));
Progress progress = new Progress();
progress.setShowProgress(jsonObject.getBoolean("ShowProgress"));
progress.setTarget(jsonObject.getInt("Target"));
// the above values are set correctly and appear if I use Log
} catch (Exception e) {
e.printStackTrace();
}
// HERE'S THE ISSUE:
// Eclipse reports "progress cannot be resolved to a variable"
return progress;
}
这是 OnPostExecute:
public void onPostExecute(ArrayList<Progress> progress) {
opportunityActivity.updateProgress(progress);
}
这是课程:
public class Progress {
private boolean showprogress;
private int target;
public boolean getShowProgress() {
return showprogress;
}
public void setShowProgress(boolean showprogress) {
this.showprogress = showprogress;
}
public int getTarget() {
return target;
}
public void setTarget(int target) {
this.target = target;
}
}
这是 onPostExecute:
public void onPostExecute(ArrayList<Progress> progress) {
opportunityActivity.updateProgress(progress);
}
它在我无法访问传递的 ArrayList 时触发的方法:
public void updateProgress(ArrayList<Progress> progress) {
progress_text = (TextView)findViewById(R.id.progress_text);
progress_text.setText("Target: " + progress.getTarget());
}