为什么我的代码在运行时会导致ArrayIndexOutOfBoundsException?

时间:2018-10-26 09:07:24

标签: java arrays

我的代码如下:

public class Meh {
    public static void main(String[] args) {
        String entries[] = { "entry1", "entry2" };
        int count = 0;
        while (entries[count++] != null) {
            System.out.println(count);
        }
        System.out.println(count);
    }
}

为什么我的代码会导致arrayindexoutofboundsexception?

1 个答案:

答案 0 :(得分:0)

我猜您正在尝试进行循环,您正在尝试从未绑定的索引中读取。这是工作代码

 The push refers to repository [registry-gitlab.mycompany.com/username/myproject/cassandra]
An image does not exist locally with the tag: registry-gitlab.mycompany.com/username/myproject/cassandra