小编Mar*_*cos的帖子

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
Run Code Online (Sandbox Code Playgroud)

我看了很多遍的代码,我似乎无法找到我在arraylist索引的位置...

这是dotProduct 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 …
Run Code Online (Sandbox Code Playgroud)

java arraylist indexoutofboundsexception

1
推荐指数
1
解决办法
2283
查看次数

更多麻烦'do while'循环,Java

在决定有目的地退出程序之前,如何让我的程序提示用户做出不同的选择?现在我尝试了一个带有一个名为'exit'的布尔值的do-while循环,试图说当exit是false时,继续提示用户选择要做什么,尽管它所做的只是询问它们一次,然后它就完成了用户需要,应用程序停止.

这是我的代码:

boolean exit = false;

do {
  int options = 0;
  do {
    options = Integer.parseInt(JOptionPane.showInputDialog(null,
              "Would you like to:"
              + "\n(Enter number value of option you would like to choose.)\n"
              + "\n1. See your recommendations. \n2. See top rated books."
              + "\n3. See random books of the day. \n4. Exit"));
  } while (logIn < 1 || logIn > 4);

  if (options == 1) {
    recommend.displayRecommendations(custIndex);
  } else if (options == 2) {
    calculations.displayTopTen();
  } else if (options == …
Run Code Online (Sandbox Code Playgroud)

java

1
推荐指数
2
解决办法
152
查看次数