当1.7很好时,Java 1.6有读取文件的运行时错误

时间:2012-08-26 11:05:51

标签: java java-6

我一直在使用JDK v1.7在我自己的电脑上完成一项任务,我必须在我的uni的Unix计算机上使用java 1.6版提交我的作业。

我的所有代码都在我的机器上正常运行,当我通过SSH连接到我的uni计算机并将代码转移到其中时,它编译也很好。但是,当我去运行它时,我收到了

NoSuchElementException: No line found

我需要读取的.xml文件大约有1000-1200个字符(文件比这长得多)。

违规方法是

private CDAlbum CDread(Scanner inLine) {
    String tempTitle = "Unknown CD";
    String tempGenre = "Unknown Genre";
    String tempArtist = "Unknown Artist";
    ArrayList<String> tempTracks = new ArrayList<String>();

    do {
        lineBuffer = inLine.nextLine();
        if (lineBuffer.equals("<Title>")) {
            tempTitle = inLine.nextLine();
            System.out.println("reading in a CD, just read title: " + tempTitle);
        } else if (lineBuffer.equals("<Genre>")) {
            tempGenre = inLine.nextLine();
        } else if (lineBuffer.equals("<Artist>")) {
            tempArtist = inLine.nextLine();
            //System.out.println("Which has artist: " + tempArtist);
        } else if (lineBuffer.equals("<Tracks>")) {
            //populate tracks array
            lineBuffer = inLine.nextLine();
            while (!(lineBuffer.equals("</Tracks>"))) {
                tempTracks.add(lineBuffer);
                //System.out.println("Read track: " + lineBuffer);
                lineBuffer = inLine.nextLine();
            }
        }
    } while (!(lineBuffer.equals("</CD>")));
    System.out.println(tempTracks);
    CDAlbum tempdisc = new CDAlbum(tempTitle, tempGenre, tempArtist, tempTracks);
    return tempdisc;
}

错误发生在

lineBuffer = inLine.nextLine();

我的调试深度有点偏离,欢迎任何可能导致此问题的建议。

控制台输出的屏幕截图:http://puu.sh/YXKN

整个源代码(以防万一,因为使用dropbox很容易):https://www.dropbox.com/sh/zz8vdzqgw296s3d/v_cfW5svHG

1 个答案:

答案 0 :(得分:0)

不再需要回答了 - 结果我弄错了,并且在运行java 1.7的Windows 7机器上标记了作业。