使用退出代码0 java

时间:2016-10-30 14:50:53

标签: java arrays

我正在使用Java编写代码,该代码必须能够打印Arraylist songs中的所有元素,并且还能够随机调整元素。它之前工作得很好,但现在突然间它甚至都不打印元素。代码现在唯一打印的是:

  

处理完成,退出代码为0

这意味着我的程序停止了。我在想,这可能与我的for循环有关吗?

public void printAllSongs(){
    System.out.println("These are your current songs in your player: ");
    for (Song song : songs){
        System.out.println(song.toString());
    }
}

public static void main(String[] args) {
    MusicMaria player = new MusicMaria();

    player.addTrack(new Song("Timberlake", "Cry me a river", 4)); 
    player.addTrack(new Song("Shakira", "Wherever", 3));
    player.addTrack(new Song("Beyonce", "Single legs", 5));
    player.addTrack(new Song("James Brown", "It's a mans world", 3));
    player.addTrack(new Song("Ed Sheeran ", "Legohouse", 3));
    player.addTrack(new Song("Mia", "I love you", 4));
    player.addTrack(new Song("Scarlet", "Palm tree", 5));
    //player.printAllSongs();
    player.shuffle();
    player.printAllSongs();
}

1 个答案:

答案 0 :(得分:2)

根据您已关联的代码(https://www.dropbox.com/sh/whhr43541u2v03j/AACJXvg7J4ftNahysx-tFDPca?dl=0),问题出在您的<ItemGroup> <DnxInvisibleFolder Include="wwwroot\" /> </ItemGroup> 方法中。

您目前所做的只是按歌曲的长度增加总播放列表长度。您需要做的是将addTrack(Song)添加到Song对象。以下是应该解决问题的代码。

ArrayList<Song>