-1
我使用這個方法來獲取對Spotify的zipfsong拼圖輸入:https://www.spotify.com/us/jobs/tech/zipfsong/這是得到這個難題的輸入的正確方法嗎?
public static ArrayList<ArrayList<String>> fileReader() throws IOException {
Scanner scanner = new Scanner(System.in);
ArrayList<ArrayList<String>> fileContents = new ArrayList<ArrayList<String>>();
try{
String currentLine = scanner.nextLine();
ArrayList<String> fileRow = new ArrayList(Arrays.asList(currentLine.split(" ")));
fileContents.add(fileRow);
int numberOfInputLines = Integer.parseInt(fileRow.get(0));
int numberOfOutputLines = Integer.parseInt(fileRow.get(1));
if (numberOfInputLines < numberOfOutputLines) {
return null;
}
for (int lineCount = 0; lineCount < numberOfInputLines; lineCount++) {
currentLine = scanner.nextLine();
fileRow = new ArrayList(Arrays.asList(currentLine.split(" ")));
fileContents.add(fileRow);
}
} catch(Exception e) {
System.out.println("Read Error");
return null;
} finally {
scanner.close();
}
return fileContents;
}
所以,我基本上都看過的第一線,發現行數來,然後用掃描儀讀取。現在,由於某種原因,我一直在獲取ArrayIndexOutOfBoundsException。是因爲這個輸入法嗎?
什麼是異常的完整堆棧跟蹤? –
當我運行它時,我不明白。但是當我提交它時,我只是得到ArrayIndexOutOfBoundsException。而已。 –
我相信我也問過你最後一個問題中的堆棧跟蹤(這幾乎完全像這個)。它有助於縮小問題範圍。 –