数组下标越界
private void nextChapter() {
params=ParseUrl.getParseInfo();
Log.e("TGA", "长度: "+params.length );
asyncTask = new HttpRequest.RequestAsyncTask(new HttpRequest.onReponseListener() {
@Override
public void success(String url) {
try {
String data=new JSONObject(url).getString("data");
Gson gson=new Gson();
BaseBean bean=gson.fromJson(data,BaseBean.class);
content.setText(bean.getContent());
title.setText(bean.getTitle());
author.setText(bean.getAuthor());
} catch (JSONException e) {
e.printStackTrace();
}
}
@Override
public void failure(String error) {
}
});
asyncTask.execute(params[count]);
count++;
Log.e("TGA", "变量: "+count );
}
public static String[] getParseInfo(){
// List<String> url=new ArrayList<>();
String[] url={"http://www.imooc.com/api/teacher?type=3&cid=1",
"http://www.imooc.com/api/teacher?type=3&cid=2",
"http://www.imooc.com/api/teacher?type=3&cid=3",
"http://www.imooc.com/api/teacher?type=3&cid=4",
"http://www.imooc.com/api/teacher?type=3&cid=5",
"http://www.imooc.com/api/teacher?type=3&cid=6",
"http://www.imooc.com/api/teacher?type=3&cid=7",
"http://www.imooc.com/api/teacher?type=3&cid=8",
"http://www.imooc.com/api/teacher?type=3&cid=9",
"http://www.imooc.com/api/teacher?type=3&cid=10",
"http://www.imooc.com/api/teacher?type=3&cid=11",
"http://www.imooc.com/api/teacher?type=3&cid=12",
"http://www.imooc.com/api/teacher?type=3&cid=13",
"http://www.imooc.com/api/teacher?
};
return url;
}
@Override
public void onClick(View v) {
switch (v.getId()){
//下一篇
case R.id.next_chapter:
nextChapter();
break;
//上一篇
case R.id.previous_posts:
previousPosts();
break;
case R.id.enshrine:
enshrine();
break;
}
}
正在回答
asyncTask.execute(params[count]); count++;
这里count没做限定,如果一直加就会数组下标越界,建议使用条件语句将上面两行代码包裹起来,例如
if(count<params.length){ asyncTask.execute(params[count]); count++; }
能给点思路怎么显示在ListView上么
- 参与学习 人
- 提交作业 307 份
- 解答问题 1613 个
本专题是联网及数据处理的必备技能。课程从网络基础知识到线程间协同工作、异步下载处理。介绍了Android内外部文件存储、轻量级数据库SQLite的使用。利用屏幕适配、状态保持、百度地图解决实际问题。
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星