I am trying to calculate the overall time of an album.
The user enters the track length (double) in format mm.ss .
Then convert this in a String so I can calculate min and sec separately.
public void overallRunningTime()
{
int min = 0;
int sec = 0;
for(int i = 0; i < album.size(); i++)
{
double songLength = album.get(i).getTrackLength();
String trackLength = String.valueOf(songLength);
String[] songLengthSplit = trackLength.split(".");
min = Integer.valueOf(songLengthSplit[0]);
sec = Integer.valueOf(songLengthSplit[1]);
if(Integer.parseInt(songLengthSplit[1]) > 60)
{
sec = Integer.valueOf(songLengthSplit[1]) % 60;
min = Integer.valueOf(songLengthSplit[1]) / 60;
}else
{
sec = Integer.valueOf(songLengthSplit[1]);
}
System.out.println("Seconds: " + sec);
System.out.println("Minutes: " + min);
// overallTime += songLength;
}
System.out.print("The overall time is: " + overallTime);
}
I get an java.lang.ArrayIndexOutOfBoundsException: 0
at this line min = Integer.valueOf(songLengthSplit[0]);