2이 코드는 약간의 도움이 필요합니다. IndexOutOfBoundsException이 발생합니다. 나는 이유를 알지만 나는 그것을 고치려고 애써왔다. 문제 : eMain.getElementsByClass ("trA1"). size() = 8 및 eMain.getElementsByClass ("trA2") size() = 7 (크기는 많이 있지만 trA1은 항상 trA2보다 큽니다. add (trA1), add (trA2), add (trA1), add (trA2) ...... (for 루프를 사용하고 있습니다.)하지만 각 요소를 ArrayList에 추가해야합니다. 요소 8, trA2 요소가 8 없기 때문에 예외가 발생합니다. 요소가 null 또는 ""있는지 확인하기 위해 If 문을 시도했지만 예외가 여전히 발생합니다. 어떤 아이디어.Arraylist에 요소를 추가 할 때 문제가 발생합니다. JSoup Android
// game list data
if (!eMain.equals("")) {
for (int i=0; i < eMain.getElementsByClass("trA1").size(); i++) {
// check if AsyncTask was cancelled
if (isCancelled())
break;
if (eMain.getElementsByClass("trA1").select("strong").get(i).text() != null) {
// get string data
String titleA1 = eMain.getElementsByClass("trA1").select("strong").get(i).text();
String achAmountA1 = eMain.getElementsByClass("trA1").select("td[align]").get(mAchAmountCounter).text();
String gsAmountA1 = eMain.getElementsByClass("trA1").select("td[align]").get(mGsAmountCounter).text();
String aPageLinkA1 = eMain.getElementsByClass("trA1").select("td a").get(mPageLinkCounter).attr("abs:href");
String iconSrcA1 = eMain.getElementsByClass("trA1").select("td a img").get(i).attr("abs:src");
// create game object
GameObject gameObjectA1 = new GameObject();
gameObjectA1.setGlTitle(titleA1);
gameObjectA1.setGlAchAmount(achAmountA1 + " achievements");
gameObjectA1.setGlGSAmount(gsAmountA1 + " gamer score");
gameObjectA1.setGlAchPageUrl(aPageLinkA1);
gameObjectA1.setGlIcon(iconSrcA1);
mGameObjectList.add(gameObjectA1);
}
if (eMain.getElementsByClass("trA2").select("strong").get(i).text() != null) {
String titleA2 = eMain.getElementsByClass("trA2").select("strong").get(i).text();
String achAmountA2 = eMain.getElementsByClass("trA2").select("td[align]").get(mAchAmountCounter).text();
String gsAmountA2 = eMain.getElementsByClass("trA2").select("td[align]").get(mGsAmountCounter).text();
String aPageLinkA2 = eMain.getElementsByClass("trA2").select("td a").get(mPageLinkCounter).attr("abs:href");
String iconSrcA2 = eMain.getElementsByClass("trA2").select("td a img").get(i).attr("abs:src");
GameObject gameObjectA2 = new GameObject();
gameObjectA2.setGlTitle(titleA2);
gameObjectA2.setGlAchAmount(achAmountA2 + " achievements");
gameObjectA2.setGlGSAmount(gsAmountA2 + " gamer score");
gameObjectA2.setGlAchPageUrl(aPageLinkA2);
gameObjectA2.setGlIcon(iconSrcA2);
mGameObjectList.add(gameObjectA2);
}
// counters
mPageLinkCounter += 3;
mAchAmountCounter += 2;
mGsAmountCounter += 2;
// update progress bar
publishProgress((100/(Integer) Math.round(eA1.size())));
}
}
귀하의 질문에 전체 스택 추적을 포함하십시오. – fge