私は次のエラーを取得していますが:OutOfBoundsExceptionのトラブル、Javaの
Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 86, Size: 86
at java.util.ArrayList.rangeCheck(ArrayList.java:604)
at java.util.ArrayList.get(ArrayList.java:382)
at Netbooks.Recommendations.getDotProduct(Recommendations.java:72)
at Netbooks.TestRecomendations.main(TestRecomendations.java:11)
Java Result: 1
私は何度もコードを見てきたと私はArrayListのインデックスの上に行く場所を見つけることができないよう... 。
public List<Integer> getDotProduct() throws IOException {
Books book = new Books();
Ratings cust = new Ratings();
PureRatings pureRatings = new PureRatings();
List<String> bookList = book.readBooks();
List<String> customerList = cust.readCustomers();
List<List<Integer>> pureRatingsList = pureRatings.parseRatingsFile();
List<Integer> dotProduct = new ArrayList<Integer>();
int index = getCustIndex();
if (index == -1) {
return dotProduct;
}
for (int i = 0; i < customerList.size(); i++) {
int sum = 0;
for (int j = 0; j < bookList.size(); i++) {
if (i == index) {
dotProduct.add(0);
} else { //Next line is line 72.
sum = sum + (pureRatingsList.get(index).get(j)) * (pureRatingsList.get(i).get(j)); //Line 72.
}
}
dotProduct.add(sum);
}
return dotProduct;
}
そして、ちょうど場合(別のクラスでは)私の主な方法:
ここは、ドット積のArrayListのコードです
public class TestRecomendations {
public static void main(String[] args) throws IOException {
Recommendations recomm = new Recommendations();
List<Integer> dotProduct = recomm.getDotProduct();//Line 11.
for (int i = 0; i < dotProduct.size(); i++) {
System.out.println(dotProduct.get(i));
}
}
}
それはちょうど私がArrayListにアイテムを無制限に追加することができるはずですので、私はライン72が問題を引き起こしているかを理解していない...
のドット積のArrayListの要素をプリントアウトする必要があります....どんな助けもありがとう。
インデックスは0から基づいています。 86番目のアイテムのリストについては、87番目のアイテム(インデックス86)にアクセスしています。索引変数が乱雑になっている可能性があります。 (例えば、あなたは[0、 'customerList.size'から' i'を反復しますが、 'pureRatingsList.get' ...で' i'を使うなど) –
デバッガを使ってみましたか? java.lang.IndexOutOfBoundsExceptionにブレークポイントを設定し、ブレークポイントが破損する理由を確認してください。 – Axel