I keep on getting a NumberFormatException in my code, but I can't seem to figure out why.
import java.io.*;
import java.util.*;
public class SongCollection
{
ArrayList<Song> songs;
public SongCollection(ArrayList<Song> songs) {
this.songs = songs;
}
public void addSong(String line) {
String[] parts = line.split("\t");
int year = Integer.parseInt(parts[0]);
int rank = Integer.parseInt(parts[1]);
String artist = parts[2];
String title = parts[3];
Song addedSong = new Song(year, rank, artist, title);
songs.add(addedSong);
}
public void printSongs(PrintStream output) {
for (int i = 0; i < songs.size(); i++) {
Song song = songs.get(i);
output.println(song.toString());
}
}
}
The string I used for the addSong method was from this input file:
The error I get is "java.lang.NumberFormatException: For input string "1965" (in java.lang.NumberFormatException)"
EDIT (adding debugger window picture):
Thank you for your help!