Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Loops java.lang.IndexOutOfBoundsException?_Loops_Exception_Indexing - Fatal编程技术网

Loops java.lang.IndexOutOfBoundsException?

Loops java.lang.IndexOutOfBoundsException?,loops,exception,indexing,Loops,Exception,Indexing,我试图显示歌曲名称列表,用户可以添加到此列表,但当我达到6首歌曲时,consle会显示这6首歌曲以及此错误 线程“main”java.lang.IndexOutOfBoundsException中的异常:索引6超出长度6的界限 这是我正在使用的代码 private static void getTrackList() { System.out.println("List all tracks."); System.out.println(cou

我试图显示歌曲名称列表,用户可以添加到此列表,但当我达到6首歌曲时,consle会显示这6首歌曲以及此错误 线程“main”java.lang.IndexOutOfBoundsException中的异常:索引6超出长度6的界限 这是我正在使用的代码

private static void getTrackList() {
        System.out.println("List all tracks.");
        System.out.println(count);
        if (myJukebox == null) {
            System.out.println(PROMPT + "Sorry, there are no tracks.");
        } else {
            System.out.println("We have the following tracks:");

            for (int index = 0; index < count; index++) {
                System.out.println(SPACES + (index + 1) + ". " + myJukebox.allTracks.get(index).getTitle());
            }
        }
        System.out.println();
        return;

    }
private static void getTrackList(){
System.out.println(“列出所有曲目”);
系统输出打印项次(计数);
如果(myJukebox==null){
System.out.println(提示+“对不起,没有音轨。”);
}否则{
System.out.println(“我们有以下跟踪:”);
for(int index=0;index
问题不在此代码中,请在填充所有曲目和“count”变量的位置添加代码。为什么使用单独的计数而不是allTracks.count()?以下是计数公共静态int count=0的代码;这里是addTrafck//将对象添加到数组myJukebox.addTrack(tk)中使用计数的地方;//递增计数++;老实说,我对java不太熟悉,所以我不确定我是在哪里用这种方式完成的