小编Len*_*mes的帖子

我的java程序给了我一个IndexOutOfBoundsException

当我的程序进入我的代码的这一部分时,它会崩溃并产生此错误

public static boolean Search(ArrayList<String> ArrayToSearch,String word)
{
    String temp;
    boolean found = false;
    for(int counter = 0;found || counter < ArrayToSearch.size();counter++)
        {
        temp = ArrayToSearch.get(counter);
        if(temp.equals(word.toLowerCase()))
        {
            found = true;
            position = counter;
        }
    }
    return found;
}
Run Code Online (Sandbox Code Playgroud)

ArrayToSearch是不同的数组列表,每行包含一个单词,代表字典.Word是用户想要搜索的单词.这是它产生的错误.Add是一个调用此方法并从中接收一个布尔值的方法

D:\>java Evan
Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 109680, Size: 109680
        at java.util.ArrayList.rangeCheck(Unknown Source)
        at java.util.ArrayList.get(Unknown Source)
        at Evan.Search(Evan.java:95)
        at Evan.Add(Evan.java:68)
        at Evan.main(Evan.java:53)

D:\>
Run Code Online (Sandbox Code Playgroud)

java runtime-error indexoutofboundsexception

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