0
我一直在使用JDK v1.7在我自己的PC上進行任務,我必須在我的uni Unix計算機上用java 1.6版提交我的任務。當1.7正常時,Java 1.6有讀取文件時出現運行時錯誤
我的所有代碼在我的機器上執行得很好,當我將SSH連入我的uni計算機並將代碼轉移到其他地方時,它也編譯得很好。然而,當我去運行它,我收到一個
NoSuchElementException: No line found
約1000-1200字符到.xml文件我需要讀取(該文件是比這更長的時間)。
違規的方法是
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();
錯誤我有點出我的調試深度的這裏,並且任何建議,這可能是導致這是歡迎。控制檯輸出的
完整的源代碼(以防萬一,因爲它很容易與Dropbox的做):不需要https://www.dropbox.com/sh/zz8vdzqgw296s3d/v_cfW5svHG